How to attach image from drawable to gmail?

后端 未结 4 1121
醉酒成梦
醉酒成梦 2020-11-28 16:49

I am trying to attach image from my gridview to gmail or facebook,but whenever i tried to attach my app got crash,and i am getting following error with nullpointer exceptio

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 17:07

    This is what worked for me perfectly.

                Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent.setType("image/jpeg");
    
                shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.share_subject));
                shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_message));
    
                shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + C.PROJECT_PATH + "/drawable/" + R.drawable.image_to_share);
    
                startActivity(Intent.createChooser(shareIntent, "Share Image"));
    

    But I will always recommend to decode a Bitmap from this resource, save it as a File in the storage and then use that file. A more reliable way this directly using from the resources.

提交回复
热议问题