Share an image from an ImageView

To share an image from an ImageView in your Sketchware Android project, in VIEW area add a Button button1, which will act as a share button.

In the event of on button1 click, use an add source directly block and put following code in it:
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"));

Now save and run the project. You should be able to share the image from imageview1.

Comments

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

How to enable upload from webview in Sketchware?

Enable Fullscreen for Youtube videos in WebView

Creating a Drawing View in Sketchware

List of Calendar Format symbols valid in Sketchware