Native Android screenshot/image sharing in Unity

This post was originally posted at https://agrawalsuneet.github.io/blogs/native-android-image-sharing-in-unity/ and reposted on Medium on 10th Aug 2018.
//Java
String screenShotPath = "fireblock_highscore.png";
Uri uriToImage = Uri.fromFile(new File("file://" + screenShotPath));
String shareSubject = "I challenge you to beat my high score in Fire Block";
String shareMessage = "I challenge you to beat my high score in Fire Block. " +
"Get the Fire Block app from the link below. \nCheers\n\n" +
"http://onelink.to/fireblock";


Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);


shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSubject);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);

shareIntent.setType("image/png");
startActivity(Intent.createChooser(shareIntent, "Share your high score"));
//Kotlin
val screenShotPath = "fireblock_highscore.png"
val
uriToImage = Uri.fromFile(File("file://" + screenShotPath))

val shareSubject = "I challenge you to beat my high score in Fire Block"
val
shareMessage = "I challenge you to beat my high score in Fire Block. " +
"Get the Fire Block app from the link below. \nCheers\n\n" +
"http://onelink.to/fireblock"

val
shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND

shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage)
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSubject)
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage)

shareIntent.type = "image/png"
startActivity(Intent.createChooser(shareIntent, "Share your high score"))

Please continue reading at https://agrawalsuneet.github.io/blogs/native-android-image-sharing-in-unity/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store