将图像共享到Gmail工作正常。当试图分享到默认"消息" Nexus S上的应用程序,"您无法将此图片添加到您的消息中#34;显示toast,图像未附加到消息。 Android版本4.1.2。
这是我的实施:
AndroidManifest :
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.package.name.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths"/>
</provider>
filepaths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>
意图:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Context context = MyApplication.getInstance().getApplicationContext();
String authority = context.getString(R.string.provider_authorities);
Uri uri = FileProvider.getUriForFile(context, authority, file)
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/png");
String titleForChooser = getString(R.string.app_chooser_title);
Intent chooser = Intent.createChooser(sendIntent, titleForChooser);
startActivityForResult(chooser, APPS_CHOOSER_REQUEST_CODE);
文件放在以下路径中:content://com.package.name.fileprovider/external_files/Android/data/com.package.name/files/share_im/155047.png
有什么问题?