簡體   English   中英

與其他應用分享圖片

[英]Share image with other apps

這是我的問題......我想分享一個png圖像。 我有可繪制和資產的圖像。 當我使用sharingIntent它工作但不是我想要的方式。 共享的文件顯示為數字而沒有擴展名,一些應用程序發送消息“未知文件”。 我能做什么??

這是我的代碼:

    Uri uri = Uri.parse("android.resource://com.example.shareimages/" + R.drawable.caja);
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);

    shareIntent.setType("image/png");

    shareIntent.putExtra(Intent.EXTRA_STREAM,  uri);

    startActivity(Intent.createChooser(shareIntent, "send"));

我嘗試使用而不是可繪制文件,資產中的文件(使用此文件:/// android_asset / ... )但它不起作用

嘗試這樣的事情:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

// For a file in shared storage.  For data in private storage, use a ContentProvider.
Uri uri = Uri.fromFile(getFileStreamPath(pathToImage));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent)

如果要通過assets文件夾共享它,則必須使用ContentProvider。 請參閱此答案,了解如何執行此操作:

https://stackoverflow.com/a/7177103/1369222

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM