Android - 分享(startActivity)在7.0上不起作用

时间:2017-05-14 22:53:18

标签: android share unity5

我正在创建一个应用程序,您可以使用应用程序内的按钮直接在whatsapp上共享.mp3。分享按钮在Android 6.0及以下版本上正常运行。但是在Android 7.0或7.1.1上,分享并不起作用。有人知道为什么这个活动在新版本上没有做任何事情吗?

这是我的共享功能

        public void sendProccess(string filePath, AudioClip clip)
{
    filePath = Application.persistentDataPath + "/" + clip.name + ".mp3";

        //instantiate the class Intent
        AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
        AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
        intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));

        //instantiate the class Uri
        AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
        AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + filePath);

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

        //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);
    }

0 个答案:

没有答案