0
我想分享一个图像到其他应用程序。 从文档中,我知道我必须创建一个ContentProvider
以确保从应用程序外部访问我的资源。它适用于大多数应用程序,但Facebook Messenger和消息(com.android.mms)。我有以下错误: FB使者:“对不起,信使无法处理文件” com.android.mms:“无法附加文件,不支持”如何使用Messenger和com.android.mms共享图像?
我在活动中调用共享代码:
Uri path = Uri.parse("content://com.myauthority/test.png");
Intent shareIntent = new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_STREAM, path).setType("image/png");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share)));
的在我的内容提供商,我只覆盖中openFile:
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
String fileName = uri.getLastPathSegment();
String resName = fileName.replaceAll(".png","");
int resId = getContext().getResources().getIdentifier(resName,"drawable",getContext().getPackageName());
File file = new File(getContext().getCacheDir(), fileName);
Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), resId);
FileOutputStream fileoutputstream = new FileOutputStream(file);
boolean flag = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileoutputstream);
try {
ParcelFileDescriptor parcelfiledescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY | ParcelFileDescriptor.MODE_WORLD_READABLE);
return parcelfiledescriptor;
} catch (IOException e) {
e.printStackTrace();
return null;
}
有没有人一个想法或经验关于这个问题分享?
谢谢。你为什么推迟分享? – znat
只是为了安全起见,如果某些手机需要很长时间才能处理数据,则需要花时间延迟。您可以更改该值。 –