0

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?

  • Please [edit] your question to explain exactly what "not working" means. – Mike M. Feb 14 '18 at 12:07
  • I edited my question – Muhammad Noamany Feb 14 '18 at 12:08
  • I think the problem might be with your urdu text in the url. For testing please try with a simple english url. Seems like encoding issue to me. – Vivek Mishra Feb 14 '18 at 12:14
  • @VivekMishra if it is an encoding issue, then why run on lollipop and not with kitkat – Muhammad Noamany Feb 14 '18 at 12:17
  • Can you open the image url https://arabian-chemistry.com/wp-content/uploads/2018/01/ما-الذي-يؤخر-العلاج-بتقنية-CRISPR؟.jpg from the kitecat device internet browser? – k3b Feb 14 '18 at 12:49
  • @k3b No, it is pop up a message "Connection Problem .. there was a network error " but on lollipop device it is loading correctly. – Muhammad Noamany Feb 14 '18 at 13:07
  • So your question is not a softwaredevelopment questioin but a network/ routing/ internetprovider/ wlan/ firewall/ proxi/ hardware/.... support question. Your app cannot do more than the buildin browser. – k3b Feb 14 '18 at 13:17

2 Answers2

2

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.

enter image description here

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.

Krupa Kakkad
  • 857
  • 1
  • 13
  • 28
Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51
0

Try this:

Picasso.with(HomeActivity.this).setLoggingEnabled(true); 

with that code you can see log of picasso.

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45