Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created February 11, 2016 20:51
Show Gist options
  • Save codenameone/6bf5e68b329ae59a25e3 to your computer and use it in GitHub Desktop.
Save codenameone/6bf5e68b329ae59a25e3 to your computer and use it in GitHub Desktop.
Sample showing off the share button in Codename One and a beavy of other API's
Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);
Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);
String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");
@codenameone
Copy link
Author

Demonstrates the elaborate use of ShareButton which includes sharing an image from the file system.

Sample usage code for ShareButton, FileSystemStorage, Image & ImageIO.

From the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment