I have an image url. I need to start the default image viewer using intent.
I tried to run it using:
Uri uri = Uri.parse("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"); Intent it = new Intent(Intent.ACTION_VIEW); it.setDataAndType(uri, "image/*") startActivity(it);
But that will not work. If I do not specify the data type, the target launches the browser, since the data is a URL. It works mostly (since you can see the image in the browser), but I would like the gallery to display the image for me.
I can also load the image into a bitmap, but I still donβt know how to display Bitmap using the gallery (if possible). Any ideas?
EDIT: I tried to save the bitmap to the cache, and then ran the viewer in this file, but it does not work. Can you spot any errors in my code? (The Utilities class is the class I wrote. The method just creates a Bitmap. It works, this is not a problem)
File temp = File.createTempFile("tempImage", ".jpg", getContext().getCacheDir()); Bitmap bmp = Utilities.loadBitmap(largeUrl.toString()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(temp)); bmp.compress(Bitmap.CompressFormat.JPEG, 90, out); out.close(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(temp), "image/jpg"); ((Activity) getContext()).startActivity(intent);
EDIT 2 : I decided that I might need the downloaded images, so I decided to save them to the SD card first. This created other problems. I asked a new question as this is a different issue.
java android android-intent
Savvas dalkitsis
source share