using System.Collections;
using UnityEngine;
using System.IO;
public class ShareResult : MonoBehaviour
{
private string screenshotFilename = "ScreenShotPintaResult.png";
public void AndroidMediaSharingClick()
{
ScreenCapture.CaptureScreenshot(screenshotFilename);
StartCoroutine(SaveAndShare(screenshotFilename));
}
IEnumerator SaveAndShare(string fileName)
{
yield return new WaitForEndOfFrame();
string shareMessage = "Test msg";
string subject = "Test subject";
string title = "Test title";
string path = Application.persistentDataPath + "/" + fileName;
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
intentObject.Call<AndroidJavaObject>("setType", "image/PNG");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TITLE"), title);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareMessage);
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject fileObject = new AndroidJavaObject("java.io.File", path);
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("fromFile", fileObject);
bool fileExist = fileObject.Call<bool>("exists");
Debug.Log("File exist : " + fileExist);
if (fileExist)
{
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
}
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
}
}