【发布时间】:2015-03-23 23:55:45
【问题描述】:
有没有办法使用Intent.ACTION_SEND 来分享屏幕截图而不需要android.permission.WRITE_EXTERNAL_STORAGE?
这是分享部分:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent chooserIntent = Intent.createChooser(shareIntent, shareTitle);
startActivity(chooserIntent);
当 uri 指向 getExternalFilesDir() 中的文件时,共享工作正常,但我更喜欢不需要 WRITE_EXTERNAL_STORAGE 权限的解决方案,以供关注隐私的用户使用。
我尝试了 3 种不同的方法:
-
文件提供者:
uri = FileProvider.getUriForFile(context, authority, imageFile);
这适用于某些共享样式 (Gmail),但不适用于其他共享样式 (Google+)。
-
上传到网络服务器:
uri = Uri.parse("http://my-image-host.com/screenshot.jpg");
这到处都失败了,导致一些(Google+)崩溃。
(我怀疑如果我自己使用每个社交网络 API 而不是 chooserIntent 来实现共享逻辑,这可能会起作用)
-
注入媒体商店:
uri = MediaStore.Images.Media.insertImage(contentResolver, bitmap, name, description);
这会引发 SecurityException,说明它需要 WRITE_EXTERNAL_STORAGE。
我还缺少其他方法吗?
【问题讨论】:
-
尝试将
FileProvider与我的LegacyCompatCursorWrapper混在一起,看看你是否有更好的运气。该包装器是my CWAC-Provider project 的一部分,here is a sample app 显示了它与FileProvider的一个小子类一起使用。如果它对 Google+ 没有帮助,请告诉我(例如,CWAC-Provider 跟踪器上的问题)。