I am viewing an image from url in an imageView
and the code works fine with android lollipop and newer versions but not working with android Kitkat and older versions, it returns a blank image rather than the url image .. this is my code : HomeActivity.java
private static final String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final ImageView imageView = (ImageView) findViewById(R.id.imageView);
final String url =
"https://arabian-chemistry.com/wp-content/uploads/2018/01/ما-الذي-يؤخر-العلاج-بتقنية-CRISPR؟.jpg";
URI I = null;
try {
URL u = new URL(url);
I = new URI(u.getProtocol(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getRef());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
final String urlEncoded = Uri.encode(url, ALLOWED_URI_CHARS);
final String ui = I.toASCIIString();
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Picasso.with(HomeActivity.this).load(ui).resize(48, 48).placeholder(R.color.colorPrimaryDark).into(imageView);
Toast.makeText(HomeActivity.this, "url is: " + ui, Toast.LENGTH_SHORT).show();
}
});
}}
activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@color/colorAccent"
tools:context="com.alpha25.gridview.HomeActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@+id/imageView"
/>
</RelativeLayout>
and I included the Internet permission in the AndroidManifest
file
Is there any suggestions?
After examining your code. I've made a demo of your problem. So I'm attaching the screenshots and all the detail including the solution to analyze your problem better and to solve it.
First of all. **In Picasso **, it indicates an error from the server . here in the log, you can see that.
I digged your problem more with better logging...
This is the info I've got from glide library ...
W/Glide: Load failed for https://arabian-chemistry.com/wp-content/uploads/2016/07/ptable.png with size [200x200] class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
Cause (1 of 1): class javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x608e5f90: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x5dafe6ed:0x00000000)
from this line.
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x5dafe6ed:0x00000000)
you can see that it's a **SSL handshake failure **. this problem arises only API <=19. SO you're facing this problem in your kitkat device.
This problem can be solved by removing the SSLv3 protocol from Enabled Protocols list . you have to make a custom socketFactory class called NoSSLv3SocketFactory
for How to implement this, you can get a reference from this post
So. after following that, your problem will be solved. Still, if you face any difficulty, you're free to feel to comment.
Try this:
Picasso.with(HomeActivity.this).setLoggingEnabled(true);
with that code you can see log of picasso.
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.