このコードを使用してこれらの画像をキャッシュしようとしています...URLをURIに変換するには?
ここで構文エラーが発生しますか?
Uri imageUri = new Uri(aURL);
ここではコードを使用しています。
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;
}
http://developer.android.com/reference/java/net/URL.html#toURI
すべてのURLがされているURIをしようと、すべてではないURIはURLです。 URIは、例えば相対パスとすることができる。 URLが有効な場合(java.net.URLオブジェクトがある場合)、以下のようにniekとして行うことができます。 –
ありがとう、私はそれをimageUri = aUrl.toUri();とwalla –
btw ..あなたは私の質問をお願いします投票してください。 –