android.os.FileUriExposedException统一为Android +7.0

时间:2018-07-21 06:43:01

标签: android unity3d screenshot

我想与文本共享截图

AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");

intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));

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

intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), "text");
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), "Subject");
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");

AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");    
currentActivity.Call("startActivity", intentObject);

在android 6.0及更低版本,在7.0及更高版本中如何使用此文件?

1 个答案:

答案 0 :(得分:1)

您需要使用FileProvider类来授予对特定文件或文件夹的访问权限,以使其可以通过API 23被其他应用访问。

Documentation