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
只是爲了安全起見,如果某些手機需要很長時間才能處理數據,則需要花時間延遲。您可以更改該值。 –