How to attach a Bitmap when launching ACTION_SEND intent

匆匆过客 提交于 2019-11-27 18:50:35
Sagar Maiyad
    String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
    Uri bmpUri = Uri.parse(pathofBmp);
    final Intent emailIntent1 = new Intent(     android.content.Intent.ACTION_SEND);
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);
    emailIntent1.setType("image/png");

Where bitmap is your bitmap object which must be store in SD Card. and then use that Uri for shareimage.

You must first save the bitmap to a file. you can save it to the app's cache

private void shareBitmap (Bitmap bitmap,String fileName) {
    try {
        File file = new File(getContext().getCacheDir(), fileName + ".png");
        FileOutputStream fOut = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
        file.setReadable(true, false);
        final Intent intent = new Intent(     android.content.Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        intent.setType("image/png");
        startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
Nas

Try this it may help you:

ByteArrayOutputStream bos = new ByteArrayOutputStream();  
yourbitmapimagename.compress(CompressFormat.PNG, 0, bos);
Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_SEND); 
intent.setType("*/*"); 
intent.putExtra(Intent.EXTRA_STREAM, bos.toByteArray());
startActivity(intent); 
haresh
 String cc=trlink.toString();
 Intent share = new Intent(Intent.ACTION_SEND);
 share.setType("text/plain");
 share.putExtra(Intent.EXTRA_TEXT,cc);
 startActivity(Intent.createChooser(share,"Share Text"));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!