/// <summary> /// Loads Texture2D from URI /// </summary> /// <returns>The from URI internal.</returns> /// <param name="uri">URI.</param> public static Texture2D TextureFromUriInternal(string uri) { if (string.IsNullOrEmpty(uri)) { return(null); } using (var resolver = ContentResolver) { var uriAjo = AndroidUri.Parse(uri); try { var stream = resolver.CallAJO("openInputStream", uriAjo); var bitmapAjo = C.AndroidGraphicsBitmapFactory.AJCCallStaticOnceAJO("decodeStream", stream); return(Texture2DFromBitmap(bitmapAjo)); } catch (Exception ex) { if (Debug.isDebugBuild) { Debug.LogException(ex); } return(null); } } }
public static AndroidJavaObject SaveShareImageToExternalStorage(Texture2D tex2D) { byte[] encoded = tex2D.Encode(ImageFormat.PNG); string saveFilePath = SaveFileToExternalStorage(encoded, GoodiesShareImageFileName, GoodiesFileFolder); return(AndroidUri.FromFile(saveFilePath)); }
public Builder SetOpenUrlIntent(string url) { var uri = AndroidUri.Parse(url); var intent = new AndroidIntent(AndroidIntent.ActionView); intent.SetData(uri); _ajo.CallAJO("setIntent", intent.AJO); return(this); }
public static void RefreshGallery(string filePath) { if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.KITKAT) { ScanFile(filePath, null); } else { var uri = AndroidUri.FromFile(filePath); var intent = new AndroidIntent(AndroidIntent.ActionMediaMounted, uri); AGUtils.SendBroadcast(intent.AJO); } }
public static void RefreshGallery(string filePath) { if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.KITKAT) { using (var c = new AndroidJavaClass(MediaScannerConnectionClass)) { c.CallStatic("scanFile", AGUtils.Activity, new[] { filePath }, null, null); } } else { var uri = AndroidUri.FromFile(filePath); var intent = new AndroidIntent(AndroidIntent.ACTION_MEDIA_MOUNTED, uri); AGUtils.SendBroadcast(intent.AJO); } }
public static AndroidJavaObject GetUriFromFilePath(string saveFilePath) { AndroidJavaObject uri; if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.N) { // Reference: http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed using (var c = new AndroidJavaClass(FileProviderClass)) { var provider = AGDeviceInfo.GetApplicationPackage() + ".multipicker.fileprovider"; uri = c.CallStaticAJO("getUriForFile", AGUtils.Activity, provider, AGUtils.NewJavaFile(saveFilePath)); } } else { uri = AndroidUri.FromFile(saveFilePath); } return(uri); }
public static AndroidJavaObject SaveShareImageToExternalStorage(Texture2D tex2D) { // aTODO update : http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed string saveFilePath = SaveImageToPictures(tex2D, GoodiesShareImageFileName, GoodiesFileFolder, ImageFormat.PNG); AndroidJavaObject uri; if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.N) { using (var c = new AndroidJavaClass(FileProviderClass)) { var provider = AGDeviceInfo.GetApplicationPackage() + ".multipicker.fileprovider"; uri = c.CallStaticAJO("getUriForFile", AGUtils.Activity, provider, AGUtils.NewJavaFile(saveFilePath)); } } else { uri = AndroidUri.FromFile(saveFilePath); } return(uri); }
/// <summary> /// Loads Texture2D from URI /// </summary> /// <returns>The from URI internal.</returns> /// <param name="uri">URI.</param> public static Texture2D TextureFromUriInternal(string uri) { if (string.IsNullOrEmpty(uri)) { return(null); } using (var resolver = ContentResolver) { var uriAjo = AndroidUri.Parse(uri); AndroidJavaObject bitmapAjo; try { var stream = resolver.CallAJO("openInputStream", uriAjo); using (var c = new AndroidJavaClass(C.AndroidGraphicsBitmapFactory)) { bitmapAjo = c.CallStaticAJO("decodeStream", stream); } var compressFormatPng = new AndroidJavaClass(C.AndroidGraphicsBitmapCompressFormat).GetStatic <AndroidJavaObject>("PNG"); var outputStream = new AndroidJavaObject(C.JavaIoBytearrayOutputStream); bitmapAjo.CallBool("compress", compressFormatPng, 100, outputStream); byte[] buffer = outputStream.Call <byte[]>("toByteArray"); var tex = new Texture2D(2, 2); tex.LoadImage(buffer); return(tex); } catch (Exception ex) { if (Debug.isDebugBuild) { Debug.LogException(ex); } return(null); } } }