我试图像这样分享一个文件:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(mAttachments.get(mCurrentPosition).url));
shareIntent.setType(mAttachments.get(mCurrentPosition).type);
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_with)));
其中mAttachments.get(mCurrentPosition).url
是指向文件的网址,例如https://dl.mywebsite.com/a_photo.jpg
或https://dl.mywebsite.com/a_file.pdf
,而mAttachments.get(mCurrentPosition).type
是mimetype。我尝试使用Gmail但遇到以下异常:
W/Gmail (21099): Error opening file to obtain size.
W/Gmail (21099): java.io.FileNotFoundException: No content provider: https://dl.mywebsite.com/a_photo.jpg
W/Gmail (21099): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1066)
W/Gmail (21099): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
W/Gmail (21099): at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:778)
W/Gmail (21099): at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:733)
...etc.
文档(http://developer.android.com/training/sharing/send.html)似乎表明您应首先将文件下载到本地存储,然后使用FileProvider
或其他内容为结果URI设置权限。是否可以在不先下载文件的情况下执行此操作?