Ok so as I have mentioned in the title, that is what I am trying to accomplish. I would think that this is something very easy to implement.
1.) Invoke somesort of screenshot method that would save the .png file to somesort of path.
2.) Get path and start an intent using the passing the path through and tada, done!
Heres what I have so far but im just not sure whats wrong here, when I click on share the "dialog menu" pops out but when I click, for instance, gmail, the image is empty? Any help would be greatly appreciated. :D
CLASS IN MY ANDROID FILES:
public class ActionResolverAndroid implements ActionResolver {
Context context;
public ActionResolverAndroid(Context context) {
this.context = context;
}
@Override
public void shareIntent() {
String filePath = Gdx.files.external("shareIMG.png").path();
System.out.println(filePath);
String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse(filePath);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(shareIntent, "Share images..."));
}
}
ATTEMPT AND MAKING IT WORK IN CORE:
buttonRate.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
button_clicked.play();
game.screenShotFactory.saveScreenshot();
game.actionResolver.shareIntent();
}
});
LASTLY, THE SCREENSHOT CLASS:
public class ScreenshotFactory {
public static void saveScreenshot(){
try
{
Gdx.files.external("shareIMG.png").delete();
FileHandle fh;
do
{
// fh = new FileHandle(Gdx.files.getLocalStoragePath() + "shareIMG.png");
fh = Gdx.files.external("shareIMG.png");
System.out.println(fh.path());
}
while (fh.exists());
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
PixmapIO.writePNG(fh, pixmap);
pixmap.dispose();
}
catch (Exception e)
{
}
}
private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown)
{
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
if (yDown)
{
// Flip the pixmap upside downx
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for (int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
pixels.clear();
}
System.out.println("SCREENSHOT TAKEN!!!");
return pixmap;
}
}