[英]Open Image from assets using external program
我編寫了內容提供程序,以使用外部應用程序(Android的標准圖像查看器)在我的應用程序包中打開png文件。 圖像存儲在資產文件夾中。
我不明白哪里出了問題,但這對我不起作用。
ContentProvider的openFile:
@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;
}
開始活動:
Uri uri = Uri.parse("file:///android_asset/image.png");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
這種方法正確嗎?我的錯誤在哪里? 還是我完全錯了?
新的活動無權訪問您的內部資產目錄。 您可以將圖像放在sdcard上,也可以使用屬於應用程序的自己的ImageView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.