Beispiel #1
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());
        }
Beispiel #2
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());
        }
Beispiel #3
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));
        }
Beispiel #4
0
        private static AndroidIntent CreateEmailIntent(string[] recipients, string subject, string body)
        {
            var uri = AndroidUtils.UriParse("mailto:");

            return(new AndroidIntent()
                   .SetAction(AndroidIntent.ACTION_SENDTO)
                   .SetData(uri)
                   .PutExtra(AndroidIntent.EXTRA_EMAIL, recipients)
                   .PutExtra(AndroidIntent.EXTRA_SUBJECT, subject)
                   .PutExtra(AndroidIntent.EXTRA_TEXT, body));
        }
Beispiel #5
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");
                }
            }
                                       );
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
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));
            }
        }
Beispiel #11
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));
            }
        }
Beispiel #12
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);
            }
        }
Beispiel #13
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);
        }
Beispiel #14
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);
            }
        }