Android 统一共享按钮实现

Android 统一共享按钮实现,android,button,unity3d,share,Android,Button,Unity3d,Share,我正在尝试实现共享功能,如本博客所示: 但当我尝试在Android上与Line共享时,我遇到了以下错误: 以下是守则的相关部分: //instantiate the class Intent AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); //instantiate the object Intent AndroidJavaObject intentObject = new Andro

我正在尝试实现共享功能,如本博客所示:

但当我尝试在Android上与Line共享时,我遇到了以下错误:

以下是守则的相关部分:

//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);
我已经花了两天的时间来寻找解决方案,任何形式的暗示都将不胜感激!即使这意味着我需要尝试其他方法来实现此共享功能


非常感谢

您是否授予外部播放器设置的写入权限?尝试执行此操作,否则图像将无法创建!:D

此代码的作者: 在PlayerSettings中授予对外部SD卡的写入权限,否则您将无法共享图片