简体   繁体   English

android KITKAT和旧版本的问题

[英]issue with android KITKAT and older versions

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 我从网址在观看图像imageView和代码工作正常使用Android Lollipop及更高版本,但不适用于Android奇巧和旧版本的工作,它返回一个空白图像,而不是URL图像..这是我的代码:HomeActivity。爪哇

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 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 我在AndroidManifest文件中包含了Internet权限

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) 错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败(外部/openssl/ssl/s23_clnt.c:741 0x5dafe6ed:0x00000000)

you can see that it's a **SSL handshake failure **. 您会看到这是** SSL握手失败**。 this problem arises only API <=19. 仅API <= 19会出现此问题。 SO you're facing this problem in your kitkat device. 因此,您在kitkat设备中正面临这个问题。

This problem can be solved by removing the SSLv3 protocol from Enabled Protocols list . 通过从“启用的协议”列表中删除SSLv3协议,可以解决此问题。 you have to make a custom socketFactory class called NoSSLv3SocketFactory 您必须创建一个名为NoSSLv3SocketFactory的自定义socketFactory类

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. 使用该代码,您可以看到毕加索的日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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