Example #1
0
        /// <summary>
        /// Take the screenshot and share using default share intent.
        /// </summary>
        /// <param name="withChooser">If set to <c>true</c> with chooser.</param>
        /// <param name="chooserTitle">Chooser title.</param>
        public static void ShareScreenshot(bool withChooser = true, string chooserTitle = "Share via...")
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            GoodiesSceneHelper.Instance.SaveScreenshotToGallery(uri =>
            {
                var intent = new AndroidIntent()
                             .SetAction(AndroidIntent.ACTION_SEND)
                             .SetType(AndroidIntent.MIMETypeImage);

                intent.PutExtra(AndroidIntent.EXTRA_STREAM, AndroidUri.Parse(uri));

                if (withChooser)
                {
                    AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle);
                }
                else
                {
                    AGUtils.StartActivity(intent.AJO);
                }
            });
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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));
            }
        }
        public static void OpenCalendarForDate(DateTime dateTime)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            // https://developer.android.com/guide/topics/providers/calendar-provider.html#intents
            long millis = dateTime.ToMillisSinceEpoch();

            using (var calendarContractClass = new AndroidJavaClass(C.AndroidProviderCalendarContract))
            {
                using (var contentUri = calendarContractClass.GetStatic <AndroidJavaObject>("CONTENT_URI"))
                {
                    using (var contentUriBuilder = contentUri.CallAJO("buildUpon"))
                    {
                        contentUriBuilder.CallAJO("appendPath", "time");
                        using (var conentUrisClass = new AndroidJavaClass(C.AndroidContentContentUris))
                        {
                            conentUrisClass.CallStaticAJO("appendId", contentUriBuilder, millis);
                        }
                        var uri    = contentUriBuilder.CallAJO("build");
                        var intent = new AndroidIntent(AndroidIntent.ActionView).SetData(uri);
                        AGUtils.StartActivity(intent.AJO);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Opens the other app on device.
        /// </summary>
        /// <param name="package">Package of the app to open.</param>
        /// <param name="onAppNotInstalled">Invoked when the app with package is not installed</param>
        public static void OpenOtherAppOnDevice(string package, Action onAppNotInstalled = null)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var pm = AGUtils.PackageManager)
            {
                try
                {
                    var launchIntent = pm.CallAJO("getLaunchIntentForPackage", package);
                    launchIntent.CallAJO("addCategory", AndroidIntent.CATEGORY_LAUNCHER);
                    AGUtils.StartActivity(launchIntent);
                }
                catch (Exception ex)
                {
                    if (Debug.isDebugBuild)
                    {
                        Debug.Log("Could not find launch intent for package:" + package + ", Error: " + ex.StackTrace);
                    }
                    if (onAppNotInstalled != null)
                    {
                        onAppNotInstalled();
                    }
                }
            }
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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);
            }
        }
Example #8
0
        /// <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);
            }
        }
Example #9
0
        /// <summary>
        /// Show the map at the given longitude and latitude at a certain zoom level.
        /// A zoom level of 1 shows the whole Earth, centered at the given lat,lng. The highest (closest) zoom level is 23.
        /// </summary>
        /// <param name="latitude">The latitude of the location. May range from -90.0 to 90.0.</param>
        /// <param name="longitude">The longitude of the location. May range from -180.0 to 180.0.</param>
        /// <param name="zoom">Zoom level.</param>
        public static void OpenMapLocation(float latitude, float longitude, int zoom = DefaultMapZoomLevel)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            if (latitude < -90.0f || latitude > 90.0f)
            {
                throw new ArgumentOutOfRangeException("latitude", "Latitude must be from -90.0 to 90.0.");
            }
            if (longitude < -180.0f || longitude > 180.0f)
            {
                throw new ArgumentOutOfRangeException("longitude", "Longitude must be from -180.0 to 180.0.");
            }
            if (zoom < MinMapZoomLevel || zoom > MaxMapZoomLevel)
            {
                throw new ArgumentOutOfRangeException("zoom", "Zoom level must be between 1 and 23");
            }

            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW);
            var uri    = AndroidUri.Parse(string.Format(MapUriFormat, latitude, longitude, zoom));

            intent.SetData(uri);

            AGUtils.StartActivity(intent.AJO);
        }
Example #10
0
        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));
            }
        }
Example #11
0
        /// <summary>
        /// Show the map at the given longitude and latitude with a certain label.
        /// </summary>
        /// <param name="latitude">The latitude of the location. May range from -90.0 to 90.0.</param>
        /// <param name="longitude">The longitude of the location. May range from -180.0 to 180.0.</param>
        /// <param name="label">Label to mark the point.</param>
        public static void OpenMapLocationWithLabel(float latitude, float longitude, string label)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            if (latitude < -90.0f || latitude > 90.0f)
            {
                throw new ArgumentOutOfRangeException("latitude", "Latitude must be from -90.0 to 90.0.");
            }
            if (longitude < -180.0f || longitude > 180.0f)
            {
                throw new ArgumentOutOfRangeException("longitude", "Longitude must be from -180.0 to 180.0.");
            }
            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentException("Label must not be null or empty");
            }

            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW);
            var uri    = AndroidUri.Parse(string.Format(MapUriFormatLabel, latitude, longitude, label));

            intent.SetData(uri);

            AGUtils.StartActivity(intent.AJO);
        }
    public void OnClick()
    {
        var intent = new AndroidIntent(AGUtils.ClassForName("com.ninevastudios.locationtracker.LocationHelperActivity"));

        intent.SetFlags(AndroidIntent.Flags.ActivityNewTask | AndroidIntent.Flags.ActivityClearTask);

        AGUtils.StartActivity(intent.AJO);
    }
        /// <summary>
        /// Launch an activity for the user to pick the current global live wallpaper.
        /// </summary>
        public static void ShowLiveWallpaperChooser()
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            var intent = new AndroidIntent(ACTION_LIVE_WALLPAPER_CHOOSER);

            AGUtils.StartActivity(intent.AJO);
        }
Example #14
0
        /// <summary>
        /// Opens the activity to modify system settings activity.
        /// </summary>
        /// <param name="onFailure">Invoked if activity could not be started.</param>
        public static void OpenModifySystemSettingsActivity(Action onFailure)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = new AndroidIntent(AndroidSettings.ACTION_MANAGE_WRITE_SETTINGS).AJO;

            AGUtils.StartActivity(intent, onFailure);
        }
Example #15
0
        public static void ShowAllAlarms()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var intent = new AndroidIntent(ACTION_SHOW_ALARMS))
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
Example #16
0
        public static void ShowAvailableWifiNetworks()
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            using (var intent = new AndroidIntent(AndroidIntent.ActionPickWifiNetwork))
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
Example #17
0
        /// <summary>
        /// Places the phone call immediately.
        ///
        /// You need <uses-permission android:name="android.permission.CALL_PHONE" /> to use this method!
        /// </summary>
        /// <param name="phoneNumber">Phone number.</param>
        public static void PlacePhoneCall(string phoneNumber)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var i = new AndroidIntent(AndroidIntent.ACTION_CALL))
            {
                i.SetData(ParsePhoneNumber(phoneNumber));
                AGUtils.StartActivity(i.AJO);
            }
        }
Example #18
0
        /// <summary>
        /// Opens systen settings window for the selected channel
        /// </summary>
        /// <param name="channelId">
        /// ID of the selected channel
        /// </param>
        public static void OpenNotificationChannelSettings(string channelId)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            var intent = new AndroidIntent(ACTION_CHANNEL_NOTIFICATION_SETTINGS);

            intent.PutExtra(EXTRA_APP_PACKAGE, AGDeviceInfo.GetApplicationPackage());
            intent.PutExtra(EXTRA_CHANNEL_ID, channelId);
            AGUtils.StartActivity(intent.AJO);
        }
Example #19
0
        /// <summary>
        /// Opens the dialer with the number provided.
        /// </summary>
        /// <param name="phoneNumber">Phone number.</param>
        public static void OpenDialer(string phoneNumber)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            using (var i = new AndroidIntent(AndroidIntent.ActionDial))
            {
                i.SetData(ParsePhoneNumber(phoneNumber));
                AGUtils.StartActivity(i.AJO);
            }
        }
 static void StartCropAndSetWallpaperActivity(AndroidJavaObject uri, AndroidRect visibleCropHint, bool allowBackup, WallpaperType which)
 {
     try
     {
         var intent = WallpaperManager.CallAJO("getCropAndSetWallpaperIntent", uri);
         AGUtils.StartActivity(intent);
     }
     catch (Exception)
     {
         Debug.Log("Setting wallpaper with crop failed, falling back to setting just image");
         var bitmapAjo = C.AndroidProviderMediaStoreImagesMedia.AJCCallStaticOnceAJO("getBitmap", AGUtils.ContentResolver, uri);
         SetWallpaperBitmap(bitmapAjo, visibleCropHint, allowBackup, which);
     }
 }
Example #21
0
        public static void SetTimer(int lengthInSeconds, string message, bool skipUi = false)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var intent = new AndroidIntent(ACTION_SET_TIMER))
            {
                intent.PutExtra(EXTRA_LENGTH, lengthInSeconds);
                intent.PutExtra(EXTRA_MESSAGE, message);
                intent.PutExtra(EXTRA_SKIP_UI, skipUi);
                AGUtils.StartActivity(intent.AJO);
            }
        }
Example #22
0
        static void OpenProfileInternal(string package, string formatUri, string profileId, string fallbackFormatUri)
        {
            var intent = GetViewProfileIntent(formatUri, profileId);

            if (package != null)
            {
                intent.SetPackage(package);
            }

            AGUtils.StartActivity(intent.AJO, () =>
            {
                var fallbackIntent = GetViewProfileIntent(fallbackFormatUri, profileId);
                AGUtils.StartActivity(fallbackIntent.AJO);
            });
        }
Example #23
0
        public static void SendTextMessageGeneric(string text, Func <bool> isInstalled, string package)
        {
            if (isInstalled())
            {
                var intent = new AndroidIntent(AndroidIntent.ActionSend)
                             .SetType(AndroidIntent.MIMETypeTextPlain)
                             .PutExtra(AndroidIntent.ExtraText, text)
                             .SetPackage(package);

                AGUtils.StartActivity(intent.AJO);
            }
            else
            {
                Debug.Log(string.Format("Can't send message because {0} is not installed", package));
            }
        }
Example #24
0
        /// <summary>
        /// Watch YouTube video. Opens video in YouTube app if its installed, falls back to browser.
        /// </summary>
        /// <param name="id">YouTube video id</param>
        public static void WatchYoutubeVideo(string id)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW, AndroidUri.Parse("vnd.youtube:" + id));

            AGUtils.StartActivity(intent.AJO, () =>
            {
                var fallbackIntent = new AndroidIntent(AndroidIntent.ACTION_VIEW,
                                                       AndroidUri.Parse("http://www.youtube.com/watch?v=" + id));
                AGUtils.StartActivity(fallbackIntent.AJO);
            });
        }
Example #25
0
        /// <summary>
        /// DIsplays the prompt to uninstall the app.
        /// </summary>
        /// <param name="package">Package to uninstall.</param>
        public static void UninstallApp(string package)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            try
            {
                var uri    = AndroidUri.Parse(string.Format("package:{0}", package));
                var intent = new AndroidIntent(AndroidIntent.ACTION_DELETE, uri);
                AGUtils.StartActivity(intent.AJO);
            }
            catch
            {
                // ignore
            }
        }
Example #26
0
        /// <summary>
        /// Opens the provided settings screen
        /// </summary>
        /// <param name="action">
        /// Screen to open. Use on of actions provided as constants in this class. Check android.provider.Settings java class for more info
        /// </param>
        public static void OpenSettingsScreen(string action)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = new AndroidIntent(action);

            if (intent.ResolveActivity())
            {
                AGUtils.StartActivity(intent.AJO);
            }
            else
            {
                Debug.LogWarning("Could not launch " + action + " settings. Check the device API level");
            }
        }
Example #27
0
        /// <summary>
        /// Open application details settings
        /// </summary>
        /// <param name="package">Package of the application to open settings</param>
        public static void OpenApplicationDetailsSettings(string package)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = new AndroidIntent(ACTION_APPLICATION_DETAILS_SETTINGS);

            intent.SetData(AndroidUri.Parse(string.Format("package:{0}", package)));
            if (intent.ResolveActivity())
            {
                AGUtils.StartActivity(intent.AJO);
            }
            else
            {
                Debug.LogWarning("Could not open application details settings for package " + package + ". Most likely application is not installed.");
            }
        }
Example #28
0
        /// <summary>
        /// Places the phone call immediately.
        ///
        /// You need <uses-permission android:name="android.permission.CALL_PHONE" /> to use this method!
        /// </summary>
        /// <param name="phoneNumber">Phone number.</param>
        public static void PlacePhoneCall(string phoneNumber)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CALL_PHONE))
            {
                Debug.LogError(AGUtils.GetPermissionErrorMessage(AGPermissions.CALL_PHONE));
                return;
            }

            using (var i = new AndroidIntent(AndroidIntent.ActionCall))
            {
                i.SetData(ParsePhoneNumber(phoneNumber));
                AGUtils.StartActivity(i.AJO);
            }
        }
Example #29
0
        /// <summary>
        /// Sends the sms using Android intent.
        /// </summary>
        /// <param name="phoneNumber">Phone number.</param>
        /// <param name="message">Message.</param>
        /// <param name="withChooser">If set to <c>true</c> with chooser.</param>
        /// <param name="chooserTitle">Chooser title.</param>
        public static void SendSms(string phoneNumber, string message, bool withChooser = true,
                                   string chooserTitle = "Send SMS...")
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = CreateSmsIntent(phoneNumber, message);

            if (withChooser)
            {
                AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle);
            }
            else
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
Example #30
0
        /// <summary>
        /// Sends the email using Android intent.
        /// </summary>
        /// <param name="recipients">Recipient email addresses.</param>
        /// <param name="subject">Subject of email.</param>
        /// <param name="body">Body of email.</param>
        /// <param name="attachment">Image to send.</param>
        /// <param name="withChooser">If set to <c>true</c> with chooser.</param>
        /// <param name="chooserTitle">Chooser title.</param>
        /// <param name="cc">Cc recipients. Cc stands for "carbon copy."
        /// Anyone you add to the cc: field of a message receives a copy of that message when you send it.
        /// All other recipients of that message can see that person you designated as a cc
        /// </param>
        /// <param name="bcc">Bcc recipients. Bcc stands for "blind carbon copy."
        /// Anyone you add to the bcc: field of a message receives a copy of that message when you send it.
        /// But, bcc: recipients are invisible to all the other recipients of the message including other bcc: recipients.
        /// </param>
        public static void SendEmail(string[] recipients, string subject, string body,
                                     Texture2D attachment = null, bool withChooser = true, string chooserTitle = "Send mail...",
                                     string[] cc          = null, string[] bcc = null)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = CreateEmailIntent(recipients, subject, body, attachment, cc, bcc);

            if (withChooser)
            {
                AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle);
            }
            else
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }