How to share screenshot with libgdx game in whatsapp and facebook?

I am developing a game using libgdx for android and ios . I already got a screenshot using this function,

public void take() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);

    Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.external("mypixmap.png"), pixmap);
    pixmap.dispose();
}

How can I share the screenshot in facebook and whatsapp?

+4
source share
1 answer

Get the path to ScreenShot and send it as shown below

Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("image/*");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(share, "Share image File"));

Note . Whatsapp does not receive images and text together.

+1
source

Source: https://habr.com/ru/post/1655570/


All Articles