sup*_*hon 6 android share image
这是我的问题......我想分享一个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"));
Run Code Online (Sandbox Code Playgroud)
我尝试使用而不是可绘制文件,资产中的文件(使用此文件:/// 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)
Run Code Online (Sandbox Code Playgroud)
如果要通过assets文件夹共享它,则必须使用ContentProvider.请参阅此答案,了解如何执行此操作: