how to share images inside assets folder with intent to other application

北战南征 提交于 2019-12-24 20:20:18

问题


i want to share images inside an assets folder using intent to the following applications

  • hangout
  • whatsapp
  • line chat
  • viber
  • tango
  • wechat

i have try this code for whatsapp but it given me file not supported

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);

    }

回答1:


You would need a ContentProvider that is capable of sharing content from assets. My StreamProvider offers this, or you could write your own.



来源:https://stackoverflow.com/questions/47182250/how-to-share-images-inside-assets-folder-with-intent-to-other-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!