简体   繁体   中英

Picasso won't load png image urls alone

I am trying to load image png image url not able to get the image if jpg file is loaded it is getting viewed only png url not working in Picasso. Have updated my Gradle dependecies for Picasso dependencies . I don't know why png image url alone couldn't be loaded . I just checked this link" https://issuetracker.google.com/issues/36912546 " but couldn't solve it. Help needed Thanks! '''

ImageView testImageview;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main22);

    testImageview = findViewById(R.id.imageView);

    String imageUri = "http://i.imgur.com/DvpvklR.png";
    ImageView ivBasicImage = (ImageView) findViewById(R.id.imageView);
    Picasso.get().load(imageUri).into(ivBasicImage);


}
}

''' My Xml code: '''

   <?xml version="1.0" encoding="utf-8"?>
   <androidx.constraintlayout.widget.ConstraintLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".Main22Activity">

   <ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="220dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/suncloud" />
    </androidx.constraintlayout.widget.ConstraintLayout>

''' My gradle file:

'''

 apply plugin: 'com.android.application'

 android {
 compileSdkVersion 29
 buildToolsVersion "29.0.2"
 defaultConfig {
    applicationId "com.example.myjson"
    minSdkVersion 15
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

Make sure you have below permission in manifest file.

<uses-permission android:name="android.permission.INTERNET" /> //uses not user

And try with this way :

 Picasso.with(getActivity()).load("http://i.imgur.com/DvpvklR.png").into(image);

And as you ars using http try Using

android:usesCleartextTraffic="true"

in Application Tag of your Manifest file! As i faced same issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM