开发者

Open Image from assets using external program

I've wrote content provider to open a png file in my app package with an external application (standard image viewer of Android). Image is stored in asset folder.

I cannot understand where is a problem, but it doesn't work for me.

openFile of ContentProvider:

   @Override
   public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
       URI file_uri = URI.create("file:///data/data/com.package/assets/image.png"); 
       File file = new File(file_uri.getPath());
       ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
       return parcel;
   }

Starting activity:

Uri uri = Uri.parse("file:///android_asset/image.png"); 
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
startActivity(int开发者_JAVA技巧ent);

Is this approach correct and where is my mistake? Or am I totally wrong?


The new Activity doesn't have access to your internal assets directory. You can either put the image on the sdcard or use your own ImageView that is part of your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜