【发布时间】:2017-11-08 14:27:13
【问题描述】:
我想使用意图将资产文件夹中的图像共享给以下应用程序
- 环聊
- 在线聊天
- 振动
- 探戈
- 微信
我已经为 whatsapp 尝试了这段代码,但它给了我不支持的文件
public void share (){
String file = "file:///android_asset/food/apple.png";
Uri filePath = Uri.fromFile(new File("content://com.example.zainabishaqmusa.postemoji/assets/gestures/aok.png"));
final ComponentName name = new ComponentName("com.whatsapp", "com.whatsapp.ContactPicker");
Intent oShareIntent = new Intent();
oShareIntent.setComponent(name);
//oShareIntent.setType("text/plain");
//oShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Website : www.google.com");
oShareIntent.putExtra(Intent.EXTRA_STREAM, filePath);
oShareIntent.setType("image/png");
oShareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Gesture.this.startActivity(oShareIntent);
}
【问题讨论】:
-
您无法以这种方式访问资产中的文件。请阅读今天的帖子,因为几个小时前也有人问过这个问题。好样的。
-
嗯,您还在使用 File 对象的内容方案。相当混乱。请删除其中一个。
-
为什么会有sharedpreferences和android-contentprovider标签?
标签: android android-intent sharedpreferences android-contentprovider