Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- public class ShareButton : MonoBehaviour {
- public string path;
- public void Share() {
- if(Application.platform == RuntimePlatform.Android) {
- AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
- AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent");
- intent.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
- if (Path.GetExtension(path) == ".mp4") {
- intent.Call<AndroidJavaObject>("setType", "video/mp4");
- }
- else {
- intent.Call<AndroidJavaObject>("setType", "image/jpeg");
- }
- AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
- AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + path);
- intent.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
- AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
- AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intent, "Share");
- currentActivity.Call("startActivity", chooser);
- }
- }
- }
Add Comment
Please, Sign In to add comment