Skip to content

Instantly share code, notes, and snippets.

@zirouan
Created August 19, 2017 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zirouan/1bb41ac6a28b4b582f77acba6541e78b to your computer and use it in GitHub Desktop.
Save zirouan/1bb41ac6a28b4b582f77acba6541e78b to your computer and use it in GitHub Desktop.
//Gerando Bitmap
public static Bitmap loadBitmapFromView(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getLayoutParams().width, view.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
view.draw(canvas);
return bitmap;
}
private void initShared(Message message) {
Bitmap bitmapShared = loadBitmapFromView(mBinding.layoutShared);
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
if (bitmapShared != null){
String pathBitmap = MediaStore.Images.Media.insertImage(getContentResolver(), loadBitmapFromView(mBinding.layoutShared),"title", null);
if (!TextUtils.isEmpty(pathBitmap)){
Uri bmpUri = Uri.parse(pathBitmap);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
sendIntent.setType("image/png");
}else{
sendIntent.putExtra(Intent.EXTRA_TEXT, message.getTextShared(mCountryLanguage));
sendIntent.setType("text/plain");
}
}else{
sendIntent.putExtra(Intent.EXTRA_TEXT, message.getTextShared(mCountryLanguage));
sendIntent.setType("text/plain");
}
startActivity(Intent.createChooser(sendIntent, getString(R.string.send_to)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment