android show image in default gallery viewer

早过忘川 提交于 2019-12-14 03:43:20

问题


I am loading some images into my activity using an AsyncTask as clickable images. On click I need to open that image in the default image viewer of the android. I am new to android. Can any one please help. My code looks like

ImageView image = new ImageView(this);
String ed="http://www.domain.com/image.jpg";
image.setTag(ed);
DownloadImagesTask td=new DownloadImagesTask(this);
td.execute(image);

image.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
         Log.v("TAGG","sdsd"); 
      }
});

Please help me.


回答1:


Gallery application does not accept URL for an image as part of the Intent. You need to save the image first. Then you can launch the default image viewer with something like this:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);


来源:https://stackoverflow.com/questions/17831562/android-show-image-in-default-gallery-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!