Reputation: 57
I am trying to fetch an image from the URL by Picasso by a simple application. My MainActivity.java
file is
'import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
Picasso.with(MainActivity.this).load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(iv);
}
}`
I Have Added Dependency For Picasso that is in build gradle which is :
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.picasso:picasso:2.5.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Here is my manifest.xml
File :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firebaseproject">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
After all of this, When I am trying to fetch this image from the URL, it is not showing anything in the app. Here Is the Screenshot of that
I am stuck in here for two days but can't find any solution after all overflow and youtube and google searches. Please help me if anyone knows how to fix this.
I am using android 10 OS in my Nokia 5.1 plus. Any Suggestions Will be appreciated. Thank you in advance.
Upvotes: 3
Views: 3539
Reputation: 3621
Sheetal answer is right to find out the issue. Google has a new feature on Android Q: filtered view for external storage. A quick fix for that is to add this code in the AndroidManifest.xml file:
<manifest ... >
<!-- This attribute is "false" by default on apps targeting Android Q. -->
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
</manifest>
You can read more about it here: https://developer.android.com/training/data-storage/compatibility
Upvotes: 0
Reputation: 154
Find below code to print exception while fetching image through Picasso
.
I have used the same version of this library that you have shared. I have tested this code into Realme 10 OS and Samsung 10. Its working.
implementation 'com.squareup.picasso:picasso:2.5.2'
In Java,
Picasso.Builder builder = new Picasso.Builder(this);
builder.listener(new Picasso.Listener()
{
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception)
{
exception.printStackTrace();
}
});
builder.build().load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(imageView);
In kotlin,
val builder = Picasso.Builder(this)
builder.listener(fun(picasso: Picasso, uri: Uri, exception: Exception) {
exception.printStackTrace()
})
builder.build().load("https://www.simplifiedcoding.net/wp-content/uploads/2015/10/advertise.png").into(imageView)
Upvotes: 3