Unity Share按钮实现

时间:2014-06-26 08:22:19

标签: android button unity3d share

我尝试实施此博客中显示的共享功能:http://www.daniel4d.com/blog/sharing-image-unity-android/

但是当我尝试将其分享到Android上的Line时,我收到了此错误:(http://triodigitalagency.com/line-error.png)。

以下是代码的相关部分:

//instantiate the class Intent
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");

//instantiate the object Intent
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");

//call setAction setting ACTION_SEND as parameter
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));

//instantiate the class Uri
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");

//instantiate the object Uri with the parse of the url's file
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse","file://"+pathName);

//call putExtra with the uri object of the file
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<AndroidJavaObject>("EXTRA_STREAM"), uriObject);

//set the type of file
intentObject.Call<AndroidJavaObject>("setType", "image/png");

//instantiate the class UnityPlayer
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

//instantiate the object currentActivity
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");

//call the activity with our Intent
currentActivity.Call("startActivity", intentObject);

我已经拉了两天头发找到解决方案,任何形式的提示都会非常感激! (即使这意味着我需要尝试其他方法来实现此共享功能)。

非常感谢!

1 个答案:

答案 0 :(得分:0)

您是否在播放器设置上授予外部写入权限?如果没有尝试这样做,你的图像将无法创建! :d

来自此代码的作者: 在PlayerSettings中授予外部写入访问权限(SDCard),否则您将无法共享图片。