【问题标题】:how to share images inside assets folder with intent to other application如何将资产文件夹中的图像共享给其他应用程序
【发布时间】:2017-11-08 14:27:13
【问题描述】:

我想使用意图将资产文件夹中的图像共享给以下应用程序

  • 环聊
  • whatsapp
  • 在线聊天
  • 振动
  • 探戈
  • 微信

我已经为 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


【解决方案1】:

您需要一个能够共享资产内容的ContentProviderMy StreamProvider offers this,或者你可以自己写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多