I am trying to cache these images using this code...
But i keep getting a syntax error here?
Uri imageUri = new Uri(aURL);
Here is the code im using.
URL aURL = new URL(myRemoteImages[position]);
Uri imageUri = new Uri(aURL);
if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists())
{
String cachFile = ""+imageUri.hashCode();
FileInputStream fis;
try {
fis = new FileInputStream(cachFile);
Bitmap bm = BitmapFactory.decodeStream(fis);
i.setImageBitmap(bm);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* Set the Width/Height of the ImageView. */
if(Build.VERSION.SDK_INT >= 11){
i.setLayoutParams(new Gallery.LayoutParams(450, 300));
}
else{
i.setLayoutParams(new Gallery.LayoutParams(125, 125));
}
} catch (FileNotFoundException e) {
Log.e("DEBUGTAG", "Remtoe Image Exception", e);
/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
/* Set the Width/Height of the ImageView. */
if(Build.VERSION.SDK_INT >= 11){
i.setLayoutParams(new Gallery.LayoutParams(450, 300));
return i;
}
i.setLayoutParams(new Gallery.LayoutParams(125, 125));
return i;
}
try this
http://www.java2s.com/Tutorials/Java/java.net/URL/Java_URL_toURI_.htm
URI uri= url.toURI()
Read the docs. You can't create an URI with an URL. Use something like
URI uri = new URI(aURL.toString());
Catching any necessary exceptions ofcourse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With