Android right way share image by intent

LIN-KEITH
LIN-KEITH
Aug 24, 2017 · 1 min read
public void shareImage(Context context,Bitmap bitmap) {
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "title", "des");
Uri uri = Uri.parse(path);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");//image/* not work
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_AsReadAdapter)));
}

// MediaStore.Images.Media.insertImage is importtant

wrong way:

Uri.from (file)

)
LIN-KEITH

Written by

LIN-KEITH

Android dev

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade