Domanda

When i press share button I want to take screen shot for my application (Activity which have the button) and share it by share intent

I try this code for taking the screen shot

 View v1 = L1.getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bm = v1.getDrawingCache();

It take a screen shot successfully But i don't know how to share it

If any one can tell me how to share this screen shot or give me another code

È stato utile?

Soluzione

To share the image, see the below function.

private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);
 
    // If you want to share a png image only, you can do:

        // setType("image/png"); OR for jpeg: setType("image/jpeg");
        share.setType("image/*");
     
        // Make sure you put example png image named myImage.png in your
        // directory
        String imagePath = Environment.getExternalStorageDirectory()
                + "/myImage.png";
     
        File imageFileToShare = new File(imagePath);
     
        Uri uri = Uri.fromFile(imageFileToShare);
        share.putExtra(Intent.EXTRA_STREAM, uri);
     
        startActivity(Intent.createChooser(share, "Share Image!"));
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top