how to share images inside assets folder with inte

2019-08-23 11:52发布

问题:

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.