How to Share an image from imageview to any app.

1) Create a new sketchware project or use an existing project.

2) For sharing images from imageview1 , set a button as button1 to initiate sharing.

3) In button1 onClick event add a ASD block and paste the below code:-

Bitmap bm = ((android.graphics.drawable.BitmapDrawable) imageview1.getDrawable()).getBitmap();
try {
java.io.File file = new java.io.File(getExternalCacheDir() + "/image.jpg");
java.io.OutputStream out = new java.io.FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) { showMessage(e.toString()); }
Intent iten = new Intent(android.content.Intent.ACTION_SEND);
iten.setType("*/*");
iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg")));
startActivity(Intent.createChooser(iten, "Send image"));

If the above code crashes consider adding WRITE EXTERNAL STORAGE by adding a more block as nothing and a blank write string to file path block.



Comments

Popular posts from this blog

How to zip files in Sketchware

Swipe Refresh WebView In sketchware

Share any file from External Storage in sketchware