示例#1
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 (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

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

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

            intent.SetData(uri);

            AndroidUtils.StartActivity(intent.JavaObj);
        }
示例#2
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 (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

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

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

            intent.SetData(uri);

            AndroidUtils.StartActivity(intent.JavaObj);
        }
示例#3
0
        /// <summary>
        /// Checks if user has any app that can handle SMS intent
        /// </summary>
        /// <returns><c>true</c>, if user has any SMS app installed, <c>false</c> otherwise.</returns>
        public static bool UserHasSmsApp()
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            return(CreateSmsIntent("123123123", "dummy").ResolveActivity());
        }
示例#4
0
        /// <summary>
        /// Determines if twitter is installed.
        /// </summary>
        /// <returns><c>true</c> if twitter is installed; otherwise, <c>false</c>.</returns>
        public static bool IsTwitterInstalled()
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            return(AndroidUtils.IsPackageInstalled(TwitterPackage));
        }
示例#5
0
        /// <summary>
        /// Checks if the user has any email app installed.
        /// </summary>
        /// <returns><c>true</c>, if the user has any email app installed, <c>false</c> otherwise.</returns>
        public static bool UserHasEmailApp()
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            return(CreateEmailIntent(new [] { "*****@*****.**" }, "dummy", "dummy").ResolveActivity());
        }
示例#6
0
        /// <summary>
        /// Checks if user has any maps apps installed.
        /// </summary>
        /// <returns><c>true</c>, if user has any maps apps installed., <c>false</c> otherwise.</returns>
        public static bool UserHasMapsApp()
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(false);
            }
            // Dummy intent just to check if any apps can handle the intent
            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW);
            var uri    = AndroidUtils.UriParse(string.Format(MapUriFormat, 0, 0, DefaultMapZoomLevel));

            return(intent.SetData(uri).ResolveActivity());
        }
        // Enables Immersive Full-Screen Mode on Android device
        // Unity 5 has added immersive mode by default, so if your using Unity 5 or above, this method is redundant.
        public static void EnableImmersiveMode(bool sticky = true)
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }
            GoodiesSceneHelper.IsInImmersiveMode = true;
            int mode = sticky ? ImmersiveFlagSticky : ImmersiveFlagNonSticky;

            AndroidUtils.RunOnUiThread(
                () => {
                var decorView = AndroidUtils.ActivityDecorView;
                decorView.Call("setSystemUiVisibility", mode);
                decorView.Dispose();
            });
        }
        /// <summary>
        /// Shows the toast with specified text.
        /// </summary>
        /// <param name="text">Text to display on toast.</param>
        /// <param name="length">Duration to show.</param>
        public static void ShowToast(string text, ToastLength length = ToastLength.Short)
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            AndroidUtils.RunOnUiThread(() =>
            {
                using (var toast = new AndroidJavaClass("android.widget.Toast"))
                {
                    var toastInstance = toast.CallStatic <AndroidJavaObject>("makeText", AndroidUtils.Activity, text, (int)length);
                    toastInstance.Call("show");
                }
            }
                                       );
        }
示例#9
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="withChooser">If set to <c>true</c> with chooser.</param>
        /// <param name="chooserTitle">Chooser title.</param>
        public static void SendEmail(string[] recipients, string subject, string body, bool withChooser = true, string chooserTitle = "Send mail...")
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = CreateEmailIntent(recipients, subject, body);

            if (withChooser)
            {
                AndroidUtils.StartActivityWithChooser(intent.JavaObj, chooserTitle);
            }
            else
            {
                AndroidUtils.StartActivity(intent.JavaObj);
            }
        }
示例#10
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 (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = CreateSmsIntent(phoneNumber, message);

            if (withChooser)
            {
                AndroidUtils.StartActivityWithChooser(intent.JavaObj, chooserTitle);
            }
            else
            {
                AndroidUtils.StartActivity(intent.JavaObj);
            }
        }
示例#11
0
        private static T GetClassStatic <T>(string clazz, string fieldName)
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(default(T));
            }

            try
            {
                using (var version = new AndroidJavaClass(clazz))
                {
                    return(version.GetStatic <T>(fieldName));
                }
            }
            catch (Exception)
            {
                Debug.LogWarning("Could not retrieve property " + fieldName + ". Check device API level");
                return(default(T));
            }
        }
示例#12
0
        /// <summary>
        /// Tweet the specified text. Will fallback to browser if official twitter app is not installed.
        /// </summary>
        /// <param name="tweet">Text to tweet.</param>
        public static void Tweet(string tweet)
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            if (IsTwitterInstalled())
            {
                var intent = new AndroidIntent(AndroidIntent.ACTION_SEND)
                             .SetType(AndroidIntent.MIMETypeTextPlain)
                             .PutExtra(AndroidIntent.EXTRA_TEXT, tweet)
                             .SetClassName(TwitterPackage, TweetActivity);

                AndroidUtils.StartActivity(intent.JavaObj);
            }
            else
            {
                Application.OpenURL("https://twitter.com/intent/tweet?text=" + WWW.EscapeURL(tweet));
            }
        }
示例#13
0
        /// <summary>
        /// Shares the text using default Android intent.
        /// </summary>
        /// <param name="subject">Subject.</param>
        /// <param name="body">Body.</param>
        /// <param name="withChooser">If set to <c>true</c> with chooser.</param>
        /// <param name="chooserTitle">Chooser title.</param>
        public static void ShareText(string subject, string body, bool withChooser = true, string chooserTitle = "Share via...")
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            var intent = new AndroidIntent()
                         .SetAction(AndroidIntent.ACTION_SEND)
                         .SetType(AndroidIntent.MIMETypeTextPlain);

            intent.PutExtra(AndroidIntent.EXTRA_SUBJECT, subject);
            intent.PutExtra(AndroidIntent.EXTRA_TEXT, body);

            if (withChooser)
            {
                AndroidUtils.StartActivityWithChooser(intent.JavaObj, chooserTitle);
            }
            else
            {
                AndroidUtils.StartActivity(intent.JavaObj);
            }
        }
示例#14
0
        /// <summary>
        /// Opens the map location with the provided address.
        /// </summary>
        /// <param name="address">Address to open.</param>
        public static void OpenMapLocation(string address)
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return;
            }

            if (string.IsNullOrEmpty(address))
            {
                throw new System.ArgumentException("Address must not be null or empty");
            }

            // Note: All strings passed in the geo URI must be encoded. For example, the string 1st & Pike, Seattle should become 1st%20%26%20Pike%2C%20Seattle.
            // Spaces in the string can be encoded with %20 or replaced with the plus sign (+).
            address = WWW.EscapeURL(address);

            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW);
            var uri    = AndroidUtils.UriParse(string.Format(MapUriFormatAddress, address));

            intent.SetData(uri);

            AndroidUtils.StartActivity(intent.JavaObj);
        }
示例#15
0
        // https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID
        /// <summary>
        /// A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device.
        /// The value may change if a factory reset is performed on the device.
        /// </summary>
        /// <returns>The unique identifier of the device.</returns>
        public static string GetAndroidId()
        {
            if (AndroidUtils.IsNotAndroidCheck())
            {
                return(string.Empty);
            }

            try
            {
                using (var objResolver = AndroidUtils.Activity.Call <AndroidJavaObject>("getContentResolver"))
                {
                    using (var clsSecure = new AndroidJavaClass("android.provider.Settings$Secure"))
                    {
                        string ANDROID_ID = clsSecure.GetStatic <string>("ANDROID_ID");
                        string androidId  = clsSecure.CallStatic <string>("getString", objResolver, ANDROID_ID);
                        return(androidId);
                    }
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }