public static void ViewFile(string fileName) { #if UNITY_ANDROID if (Application.isEditor) { return; } //FileType fileType = GetFileType(fileName); //if(fileType == FileType.notSupported) //{ // Debug.LogError($"{fileName} is not supported file type!"); // return; //} //string intentType = "application/" + fileType.ToString(); AndroidJavaObject currentActivity = NativeUnityUtil.currentActivity; NativeIntent intent = new NativeIntent("ACTION_VIEW"); AndroidJavaObject uriObject = GetUri(currentActivity, currentActivity.Call <string>("getPackageName") + ".fileprovider", fileName); //NativeIntentUtil.SetDataAndType(intentObject, uriObject, intentType); intent.SetData(uriObject); intent.SetFlags("FLAG_ACTIVITY_CLEAR_TOP", "FLAG_GRANT_READ_URI_PERMISSION", "FLAG_ACTIVITY_NO_HISTORY"); intent.CreateChooser("View File"); #else Debug.LogError("ViewFile is not supported in this platform."); #endif }
public static void SendFile(string fileName) { #if UNITY_ANDROID if (Application.isEditor) { return; } string intentType = NativeIntent.GetMIMEType(fileName); AndroidJavaObject currentActivity = NativeUnityUtil.currentActivity; NativeIntent intent = new NativeIntent("ACTION_SEND"); AndroidJavaObject uriObject = GetUri(currentActivity, currentActivity.Call <string>("getPackageName") + ".fileprovider", fileName); intent.PutExtraStream(uriObject); intent.SetType(intentType); intent.SetFlags("FLAG_ACTIVITY_CLEAR_TOP", "FLAG_GRANT_READ_URI_PERMISSION", "FLAG_ACTIVITY_NO_HISTORY"); intent.CreateChooser("Send File"); #else Debug.LogError("ViewFile is not supported in this platform."); #endif }