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?