在意图中共享失败 [英] Sharing Failed in Intent
本文介绍了在意图中共享失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用intent发送图像,如下所示:
I am trying to send image using intent as below :
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mArray[position]));
shareIntent.setType("image/png");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
编辑:文件图像阵列
private void createDrawbleArray(File fileDir) {
mArray = new File[Constants.TOTAL_GRID_ICONS];
TypedArray tArray = getResources().obtainTypedArray(R.array._images);
for (int i = 0; i < Constants.TOTAL_GRID_ICONS; i++) {
mArray[i] = getFileForResource(this, tArray.getResourceId(i, -1), fileDir, "a" + i + ".png");
}
tArray.recycle();
}
编辑:许可
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
但不幸的是,它让我分享失败了。
可能是什么问题?
But, unfortunately its giving me Sharing failed toast. What might be the issue ?
谢谢。
推荐答案
由于您的图像文件位置在项目中,因此您无法与外部应用共享图像。
As your image file location is within your project you can't share image with external app.
以下是几种分享方式
-
创建文件提供程序
create your file provider
将您的图像文件存储在外部目录中。
store your image file in external directory.
检查这些链接以创建文件提供商
check these links to create your file provider
https://developer.android.com/reference/android/support/v4/content/FileProvider.html
http://www.blogc.at/2014/03/23/share-private-files-with-other-apps-fileprovider/
这篇关于在意图中共享失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文