Exemplo n.º 1
0
        /// <summary>
        ///     Checks whether the specified permission was granted by the user.
        /// </summary>
        /// <param name="permission">Permission to check</param>
        /// <returns>Whether the specified permission was granted by the user.</returns>
        public static bool IsPermissionGranted(string permission)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            if (string.IsNullOrEmpty(permission))
            {
                throw new ArgumentException("Permission must not be null or empty", "permission");
            }

            try
            {
                using (var c = new AndroidJavaClass(C.AndroidSupportV4ContentContextCompat))
                {
                    return(c.CallStaticInt("checkSelfPermission", AGUtils.Activity, permission) == PERMISSION_GRANTED);
                }
            }
            catch (Exception ex)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning(
                        "Could not check if runtime permission is granted. Check if Android version is 6.0 (API level 23) or higher. " +
                        ex.Message);
                }
                return(false);
            }
        }
Exemplo n.º 2
0
 public static int ToJavaColor(this Color color)
 {
     using (var c = new AndroidJavaClass("android.graphics.Color"))
     {
         return(c.CallStaticInt("argb", color.a, color.r, color.g, color.b));
     }
 }
        static int AndroidColor(int alpha,
                                int red,
                                int green,
                                int blue)
        {
            if (AGUtils.IsNotAndroid())
            {
                return(0);
            }

            using (var c = new AndroidJavaClass("android.graphics.Color"))
            {
                return(c.CallStaticInt("argb", alpha, red, green, blue));
            }
        }