Guest User

Untitled

a guest
Nov 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5.  
  6. public class ShareButton : MonoBehaviour {
  7.  
  8. public string path;
  9.  
  10. public void Share() {
  11. if(Application.platform == RuntimePlatform.Android) {
  12. AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
  13. AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  14.  
  15. AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent");
  16. intent.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
  17.  
  18. if (Path.GetExtension(path) == ".mp4") {
  19. intent.Call<AndroidJavaObject>("setType", "video/mp4");
  20. }
  21. else {
  22. intent.Call<AndroidJavaObject>("setType", "image/jpeg");
  23. }
  24.  
  25. AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
  26. AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + path);
  27.  
  28. intent.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
  29. AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
  30. AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser", intent, "Share");
  31. currentActivity.Call("startActivity", chooser);
  32. }
  33. }
  34.  
  35. }
Add Comment
Please, Sign In to add comment