public static void SendMms(string phoneNumber, string message, Texture2D image = null, bool withChooser = true, string chooserTitle = "Send MMS...") { if (AGUtils.IsNotAndroid()) { return; } var intent = new AndroidIntent(AndroidIntent.ActionSend); intent.PutExtra("address", phoneNumber); intent.PutExtra("subject", message); if (image != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(image); intent.PutExtra(AndroidIntent.ExtraStream, imageUri); intent.SetType(AndroidIntent.MIMETypeImagePng); } if (withChooser) { AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle); } else { AGUtils.StartActivity(intent.AJO); } }
static AndroidIntent CreateEmailIntent(string[] recipients, string subject, string body, Texture2D attachment = null, string[] cc = null, string[] bcc = null) { var uri = AndroidUri.Parse("mailto:"); var intent = new AndroidIntent() .SetAction(AndroidIntent.ActionSendTo) .SetData(uri) .PutExtra(AndroidIntent.ExtraEmail, recipients) .PutExtra(AndroidIntent.ExtraSubject, subject) .PutExtra(AndroidIntent.ExtraText, body); if (cc != null) { intent.PutExtra(AndroidIntent.ExtraCc, cc); } if (bcc != null) { intent.PutExtra(AndroidIntent.ExtraBcc, bcc); } if (attachment != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(attachment); intent.PutExtra(AndroidIntent.ExtraStream, imageUri); } return(intent); }
public static void SendMms(string phoneNumber, string message, Texture2D image = null, bool withChooser = true, string chooserTitle = "Send MMS...") { if (AGUtils.IsNotAndroidCheck()) { return; } var intent = new AndroidIntent(AndroidIntent.ACTION_SEND); intent.PutExtra("address", phoneNumber); intent.PutExtra("sms_body", message); if (image != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveShareImageToExternalStorage(image); intent.PutExtra(AndroidIntent.EXTRA_STREAM, imageUri); intent.SetType(AndroidIntent.MIMETypeImagePng); } if (withChooser) { AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle); } else { AGUtils.StartActivity(intent.AJO); } }
public static void Tweet(string tweet, Texture2D image = null) { if (AGUtils.IsNotAndroidCheck()) { return; } if (IsTwitterInstalled()) { var intent = new AndroidIntent(AndroidIntent.ACTION_SEND) .SetType(AndroidIntent.MIMETypeTextPlain) .PutExtra(AndroidIntent.EXTRA_TEXT, tweet) .SetClassName(TwitterPackage, TweetActivity); if (image != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveShareImageToExternalStorage(image); intent.PutExtra(AndroidIntent.EXTRA_STREAM, imageUri); } AGUtils.StartActivity(intent.AJO); } else { Application.OpenURL("https://twitter.com/intent/tweet?text=" + WWW.EscapeURL(tweet)); } }
private static AndroidIntent CreateEmailIntent(string[] recipients, string subject, string body, Texture2D attachment = null, string[] cc = null, string[] bcc = null) { var uri = AndroidUri.Parse("mailto:"); var intent = new AndroidIntent() .SetAction(AndroidIntent.ACTION_SENDTO) .SetData(uri) .PutExtra(AndroidIntent.EXTRA_EMAIL, recipients) .PutExtra(AndroidIntent.EXTRA_SUBJECT, subject) .PutExtra(AndroidIntent.EXTRA_TEXT, body); if (cc != null) { intent.PutExtra(AndroidIntent.EXTRA_CC, cc); } if (bcc != null) { intent.PutExtra(AndroidIntent.EXTRA_BCC, bcc); } if (attachment != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveShareImageToExternalStorage(attachment); intent.PutExtra(AndroidIntent.EXTRA_STREAM, imageUri); } return(intent); }
/// <summary> /// Shares the text with image using default Android intent. /// </summary> /// <param name="subject">Subject.</param> /// <param name="body">Body.</param> /// <param name="image">Image to send.</param> /// <param name="withChooser">If set to <c>true</c> with chooser.</param> /// <param name="chooserTitle">Chooser title.</param> public static void ShareTextWithImage(string subject, string body, Texture2D image, bool withChooser = true, string chooserTitle = "Share via...") { if (AGUtils.IsNotAndroidCheck()) { return; } if (image == null) { throw new ArgumentNullException("image", "Image must not be null"); } var intent = new AndroidIntent() .SetAction(AndroidIntent.ACTION_SEND) .SetType(AndroidIntent.MIMETypeImage) .PutExtra(AndroidIntent.EXTRA_SUBJECT, subject) .PutExtra(AndroidIntent.EXTRA_TEXT, body); var imageUri = AndroidPersistanceUtilsInternal.SaveShareImageToExternalStorage(image); intent.PutExtra(AndroidIntent.EXTRA_STREAM, imageUri); if (withChooser) { AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle); } else { AGUtils.StartActivity(intent.AJO); } }
public static void ShareTextWithImage(string subject, string body, Texture2D image, bool withChooser = true, string chooserTitle = "Share via...") { if (AGUtils.IsNotAndroid()) { return; } if (image == null) { throw new ArgumentNullException("image", "Image must not be null"); } var intent = new AndroidIntent() .SetAction(AndroidIntent.ActionSend) .SetType(AndroidIntent.MIMETypeImageJpeg) .PutExtra(AndroidIntent.ExtraSubject, subject) .PutExtra(AndroidIntent.ExtraText, body); var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(image); intent.PutExtra(AndroidIntent.ExtraStream, imageUri); if (withChooser) { AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle); } else { AGUtils.StartActivity(intent.AJO); } }
public static void Tweet(string tweet, Texture2D image = null) { if (AGUtils.IsNotAndroid()) { return; } if (IsTwitterInstalled()) { var intent = new AndroidIntent(AndroidIntent.ActionSend) .SetType(AndroidIntent.MIMETypeTextPlain) .PutExtra(AndroidIntent.ExtraText, tweet) .SetPreferredActivity(TwitterPackage, "composer"); if (image != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(image); intent.PutExtra(AndroidIntent.ExtraStream, imageUri); } AGUtils.StartActivity(intent.AJO); } else { Application.OpenURL("https://twitter.com/intent/tweet?text=" + UnityWebRequest.EscapeURL(tweet)); } }
public static void RefreshFile([NotNull] string filePath) { Check.Argument.IsStrNotNullOrEmpty(filePath, "path"); if (AGUtils.IsNotAndroid()) { return; } AndroidPersistanceUtilsInternal.RefreshGallery(filePath); }
/// <summary> /// Saves the image to android gallery. /// </summary> /// <returns>The image to save to the gallery.</returns> /// <param name="texture2D">Texture2D to save.</param> /// <param name="title">Title.</param> /// <param name="folder">Inner folder in Pictures directory. Must be a valid folder name. /// If not specified the image will be save to default pictures folder</param> /// <param name="imageFormat">Image format.</param> public static void SaveImageToGallery(Texture2D texture2D, string title, string folder = null, ImageFormat imageFormat = ImageFormat.PNG) { if (AGUtils.IsNotAndroidCheck()) { return; } if (texture2D == null) { throw new ArgumentNullException("texture2D", "Image to save cannot be null"); } AndroidPersistanceUtilsInternal.SaveImageToPictures(texture2D, title, folder, imageFormat); }
/// <summary> /// Sets provided texture as wallpaper /// </summary> /// <param name="wallpaperTexture">Image to set as wallpeper.</param> public static void SetWallpaper([NotNull] Texture2D wallpaperTexture) { if (wallpaperTexture == null) { throw new ArgumentNullException("wallpaperTexture"); } if (AGUtils.IsNotAndroidCheck()) { return; } var wallpaperPath = AndroidPersistanceUtilsInternal.SaveWallpaperImageToExternalStorage(wallpaperTexture); SetWallpaperFromFilePath(wallpaperPath); }
/// <summary> /// <remarks> /// WARNING: This method work on my devices but always crashes on emulators and I can't find a way to fix it. /// It may be something with emulator but use this method with care and test careffuly before using it. /// </remarks> /// /// Sets provided texture as wallpaper allowing user to crop beforehand /// </summary> /// <param name="wallpaperTexture">Image to set as wallpeper.</param> public static void ShowCropAndSetWallpaperChooser([NotNull] Texture2D wallpaperTexture) { if (wallpaperTexture == null) { throw new ArgumentNullException("wallpaperTexture"); } if (AGUtils.IsNotAndroidCheck()) { return; } if (AGDeviceInfo.SDK_INT < AGDeviceInfo.VersionCodes.KITKAT) { return; } var uri = AndroidPersistanceUtilsInternal.SaveWallpaperImageToExternalStorageUri(wallpaperTexture); StartCropAndSetWallpaperActivity(uri); }
public static void SendImageGeneric(Texture2D image, Func <bool> isInstalled, string package) { if (isInstalled()) { var intent = new AndroidIntent(AndroidIntent.ActionSend) .SetType(AndroidIntent.MIMETypeImageAll) .SetPackage(package); if (image != null) { var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(image); intent.PutExtra(AndroidIntent.ExtraStream, imageUri); } AGUtils.StartActivity(intent.AJO); } else { Debug.Log(string.Format("Can't send image because {0} is not installed", package)); } }
public static void OpenPdf(string path) { if (AGUtils.IsNotAndroid()) { return; } if (!File.Exists(path)) { Debug.LogError("File doesn't exist: " + path); return; } var fileUri = AndroidPersistanceUtilsInternal.GetUriFromFilePath(path); var intent = new AndroidIntent(AndroidIntent.ActionView); intent.SetDataAndType(fileUri, AndroidIntent.MIMETypePdf); intent.SetFlags(AndroidIntent.Flags.GrantReadUriPermission | AndroidIntent.Flags.ActivityClearTop); AGUtils.StartActivity(intent.AJO); }
/// <summary> /// <remarks> /// WARNING: This method works on my devices but always crashes on emulators and I can't find a way to fix it. /// It may be something with emulator but use this method with care and test carefully before using it. /// </remarks> /// Sets provided texture as wallpaper allowing user to crop beforehand /// </summary> /// <param name="wallpaperTexture"> A texture, that will supply the wallpaper imagery.</param> /// <param name="visibleCropHint"> /// The rectangular subregion of fullImage that should be displayed as wallpaper. Passing null for this parameter means /// that the full image should be displayed if possible given the image's and device's aspect ratios, etc. /// </param> /// <param name="allowBackup"> /// True if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise. /// </param> /// <param name="which"> /// Which wallpaper to configure with the new imagery. /// </param> public static void ShowCropAndSetWallpaperChooser([NotNull] Texture2D wallpaperTexture, AndroidRect visibleCropHint = null, bool allowBackup = true, WallpaperType which = WallpaperType.Unspecified) { if (wallpaperTexture == null) { throw new ArgumentNullException("wallpaperTexture"); } if (AGUtils.IsNotAndroid()) { return; } if (AGDeviceInfo.SDK_INT < AGDeviceInfo.VersionCodes.KITKAT) { return; } var uri = AndroidPersistanceUtilsInternal.SaveWallpaperImageToExternalStorageUri(wallpaperTexture); StartCropAndSetWallpaperActivity(uri, visibleCropHint, allowBackup, which); }
/// <summary> /// /// <remarks> /// WARNING: This method work on my devices but always crashes on emulators and I can't find a way to fix it. /// It may be something with emulator but use this method with care and test careffuly before using it. /// </remarks> /// /// Sets provided image on the provided filepath as wallpaper allowing user to crop beforehand. File MUST exist. /// </summary> /// <param name="imagePath">File path to the image file</param> public static void ShowCropAndSetWallpaperChooser([NotNull] string imagePath) { if (imagePath == null) { throw new ArgumentNullException("imagePath"); } if (AGUtils.IsNotAndroidCheck()) { return; } if (AGDeviceInfo.SDK_INT < AGDeviceInfo.VersionCodes.KITKAT) { return; } CheckIfFileExists(imagePath); var uri = AndroidPersistanceUtilsInternal.GetUriFromFilePath(imagePath); StartCropAndSetWallpaperActivity(uri); }
/// <summary> /// Sets provided texture as wallpaper /// </summary> /// <param name="wallpaperTexture"> A texture, that will supply the wallpaper imagery.</param> /// <param name="visibleCropHint"> /// The rectangular subregion of fullImage that should be displayed as wallpaper. Passing null for this parameter means /// that the full image should be displayed if possible given the image's and device's aspect ratios, etc. /// </param> /// <param name="allowBackup"> /// True if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise. /// </param> /// <param name="which"> /// Which wallpaper to configure with the new imagery. /// </param> public static void SetWallpaper([NotNull] Texture2D wallpaperTexture, AndroidRect visibleCropHint = null, bool allowBackup = true, WallpaperType which = WallpaperType.Unspecified) { if (wallpaperTexture == null) { throw new ArgumentNullException("wallpaperTexture"); } if (AGUtils.IsNotAndroid()) { return; } var wallpaperPath = AndroidPersistanceUtilsInternal.SaveWallpaperImageToExternalStorage(wallpaperTexture); if (Check.IsSdkGreaterOrEqual(AGDeviceInfo.VersionCodes.N)) { SetWallpaperBitmap(AGUtils.DecodeBitmap(wallpaperPath), visibleCropHint, allowBackup, which); return; } SetWallpaperBitmap(AGUtils.DecodeBitmap(wallpaperPath)); }
/// <summary> /// <remarks> /// WARNING: This method works on my devices but always crashes on emulators and I can't find a way to fix it. /// It may be something with emulator but use this method with care and test carefully before using it. /// </remarks> /// Sets provided image on the provided filepath as wallpaper allowing user to crop beforehand. File MUST exist. /// </summary> /// <param name="imagePath"> A path to the image file </param> /// <param name="visibleCropHint"> /// The rectangular subregion of fullImage that should be displayed as wallpaper. Passing null for this parameter means /// that the full image should be displayed if possible given the image's and device's aspect ratios, etc. /// </param> /// <param name="allowBackup"> /// True if the OS is permitted to back up this wallpaper image for restore to a future device; false otherwise. /// </param> /// <param name="which"> /// Which wallpaper to configure with the new imagery. /// </param> public static void ShowCropAndSetWallpaperChooser([NotNull] string imagePath, AndroidRect visibleCropHint = null, bool allowBackup = true, WallpaperType which = WallpaperType.Unspecified) { if (imagePath == null) { throw new ArgumentNullException("imagePath"); } if (AGUtils.IsNotAndroid()) { return; } if (AGDeviceInfo.SDK_INT < AGDeviceInfo.VersionCodes.KITKAT) { return; } CheckIfFileExists(imagePath); var uri = AndroidPersistanceUtilsInternal.GetUriFromFilePath(imagePath); StartCropAndSetWallpaperActivity(uri, visibleCropHint, allowBackup, which); }
public static void ShareVideo(string videoPathOnDisc, string title, string chooserTitle = "Share Video") { if (AGUtils.IsNotAndroid()) { return; } if (!File.Exists(videoPathOnDisc)) { Debug.LogError("File (video) does not exist to share: " + videoPathOnDisc); return; } AGUtils.RunOnUiThread(() => AndroidPersistanceUtilsInternal.ScanFile(videoPathOnDisc, (path, uri) => { var intent = new AndroidIntent(AndroidIntent.ActionSend); intent.SetType("video/*"); intent.PutExtra(AndroidIntent.ExtraSubject, title); intent.PutExtra(AndroidIntent.ExtraStream, uri); AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle); })); }