Exemple #1
0
        /// <summary>
        /// Prints an HTML page from the URL.
        /// </summary>
        /// <param name="htmlUrl">URL of the HTML page.</param>
        /// <param name="jobName">The name of the print job.</param>
        public static void PrintHtmlPageFromUrl([NotNull] string htmlUrl, [NotNull] string jobName)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (htmlUrl == null)
            {
                throw new ArgumentNullException("htmlUrl");
            }

            if (jobName == null)
            {
                throw new ArgumentNullException("jobName");
            }

            var webView = C.PrintHelperUtilsClass.AJCCallStaticOnceAJO("createWebView", AGUtils.Activity, jobName);

            webView.Call("loadUrl", htmlUrl);
        }
Exemple #2
0
        /// <summary>
        /// Prints an HTML page from the source.
        /// </summary>
        /// <param name="htmlText">Text in HTML format.</param>
        /// <param name="jobName">The name of the print job.</param>
        public static void PrintHtmlPage([NotNull] string htmlText, [NotNull] string jobName)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (htmlText == null)
            {
                throw new ArgumentNullException("htmlText");
            }

            if (jobName == null)
            {
                throw new ArgumentNullException("jobName");
            }

            var webView = C.PrintHelperUtilsClass.AJCCallStaticOnceAJO("createWebView", AGUtils.Activity, jobName);

            webView.Call("loadDataWithBaseURL", string.Empty, htmlText, "text/HTML", "UTF-8", string.Empty);
        }
Exemple #3
0
        /// <summary>
        /// Removes value
        /// </summary>
        /// <param name="preferenceFileKey">Desired preferences file. If a preferences file by this name does not exist, it will be created.</param>
        /// <param name="key">The name of the preference to remove.</param>
        /// <param name="mode">Operating mode. Use 0 or MODE_PRIVATE for the default operation.</param>
        /// <returns>Returns true if the new values were successfully written to persistent storage.</returns>
        public static bool Remove(string preferenceFileKey, string key, int mode = MODE_PRIVATE)
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }
            if (string.IsNullOrEmpty(preferenceFileKey))
            {
                throw new ArgumentException("preferenceFileKey");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("key");
            }
            using (var editor = GetEditorInternal(preferenceFileKey, mode))
            {
                editor.CallAJO("remove", key);
                return(Commit(editor));
            }
        }
Exemple #4
0
        public SignalStrengths(AndroidJavaObject ajo)
        {
            if (AGUtils.IsNotAndroid() || !Check.IsSdkGreaterOrEqual(AGDeviceInfo.VersionCodes.P))
            {
                return;
            }

            if (ajo.IsJavaNull())
            {
                return;
            }

            cdmaDbm           = ajo.CallInt("getCdmaDbm");
            cdmaEcio          = ajo.CallInt("getCdmaEcio");
            evdoDbm           = ajo.CallInt("getEvdoDbm");
            evdoEcio          = ajo.CallInt("getEvdoEcio");
            evdoSnr           = ajo.CallInt("getEvdoSnr");
            gsmBitErrorRate   = ajo.CallInt("getGsmBitErrorRate");
            gsmSignalStrength = ajo.CallInt("getGsmSignalStrength");
            level             = ajo.CallInt("getLevel");
            isGsm             = ajo.CallBool("isGsm");
        }
        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);
        }
Exemple #6
0
        public static bool IsPackageInstalled(string package)
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            using (AndroidJavaObject pm = AGUtils.PackageManager)
            {
                try
                {
                    const int GET_ACTIVITIES = 1;
                    pm.Call <AndroidJavaObject>("getPackageInfo", package, GET_ACTIVITIES);
                    return(true);
                }
                catch (AndroidJavaException e)
                {
                    Debug.LogWarning(e);
                    return(false);
                }
            }
        }
        /// <summary>
        /// Displays message dialog with positive button only
        /// </summary>
        /// <param name="title">Dialog title</param>
        /// <param name="message">Dialog message</param>
        /// <param name="positiveButtonText">Text for positive button</param>
        /// <param name="onPositiveButtonClick">Positive button callback</param>
        /// <param name="onDismiss">On dismiss callback</param>
        /// <param name="theme">Dialog theme</param>
        public static void ShowMessageDialog(string title, string message, string positiveButtonText,
                                             Action onPositiveButtonClick,
                                             Action onDismiss    = null,
                                             AGDialogTheme theme = AGDialogTheme.Default)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (onPositiveButtonClick == null)
            {
                throw new ArgumentNullException("onPositiveButtonClick", "Button callback cannot be null");
            }

            AGUtils.RunOnUiThread(() =>
            {
                var builder = CreateMessageDialogBuilder(title, message, positiveButtonText, onPositiveButtonClick, onDismiss).SetTheme(theme);
                var dialog  = builder.Create();
                dialog.Show();
            });
        }
        /// <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);
        }
Exemple #9
0
        public static void RecordVideo(Action <VideoPickResult> onSuccess, Action <string> onError,
                                       bool generatePreviewImages = true)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            Check.Argument.IsNotNull(onSuccess, "onSuccess");
            Check.Argument.IsNotNull(onError, "onError");

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CAMERA))
            {
                onError(AGUtils.GetPermissionErrorMessage(AGPermissions.CAMERA));
                return;
            }

            _onVideoSuccessAction = onSuccess;
            _onVideoCancelAction  = onError;

            AGActivityUtils.PickVideoCamera(generatePreviewImages);
        }
Exemple #10
0
        public static void SetAlarm(int hour, int minute, string message, AlarmDays[] days = null,
                                    bool vibrate = true, bool skipUI = false)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            using (var intent = new AndroidIntent(ACTION_SET_ALARM))
            {
                intent.PutExtra(EXTRA_HOUR, hour);
                intent.PutExtra(EXTRA_MINUTES, minute);
                intent.PutExtra(EXTRA_MESSAGE, message);
                if (days != null)
                {
                    intent.PutExtra(EXTRA_DAYS, CreateDaysArrayList(days));
                }
                intent.PutExtra(EXTRA_VIBRATE, vibrate);
                intent.PutExtra(EXTRA_SKIP_UI, skipUI);

                AGUtils.StartActivity(intent.AJO);
            }
        }
Exemple #11
0
        static bool IsNetworkConnected(int networkType)
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            AndroidJavaObject networkInfo;

            try
            {
                networkInfo = AGSystemService.ConnectivityService.CallAJO("getNetworkInfo", networkType);
                if (networkInfo.IsJavaNull())
                {
                    return(false);
                }
            }
            catch (/* Null */ Exception)
            {
                return(false);
            }
            return(networkInfo.Call <bool>("isConnected"));
        }
        public static float GetBatteryChargeLevel()
        {
            if (AGUtils.IsNotAndroid())
            {
                return(0f);
            }

            using (BatteryChangeIntentFilter)
            {
                using (BatteryChangeIntentReceiver)
                {
                    var level = BatteryChangeIntentReceiver.CallInt(GetIntExtraMethod, ExtraLevel, -1);
                    var scale = BatteryChangeIntentReceiver.CallInt(GetIntExtraMethod, ExtraScale, -1);

                    if (level == -1 || scale == -1)
                    {
                        return(50.0f);
                    }

                    return(level / (float)scale * 100.0f);
                }
            }
        }
        /// <summary>
        /// Opens the map location with the provided address.
        /// </summary>
        /// <param name="address">Address to open.</param>
        public static void OpenMapLocation(string address)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (string.IsNullOrEmpty(address))
            {
                throw new 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 = UnityWebRequest.EscapeURL(address);

            var intent = new AndroidIntent(AndroidIntent.ActionView);
            var uri    = AndroidUri.Parse(string.Format(MapUriFormatAddress, address));

            intent.SetData(uri);

            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 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);
        }
        /// <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));
        }
Exemple #16
0
        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);
            }));
        }
Exemple #17
0
        public static void ShareText(string subject, string body, bool withChooser = true,
                                     string chooserTitle = "Share via...")
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            var intent = new AndroidIntent(AndroidIntent.ActionSend)
                         .SetType(AndroidIntent.MIMETypeTextPlain);

            intent.PutExtra(AndroidIntent.ExtraSubject, subject);
            intent.PutExtra(AndroidIntent.ExtraText, body);

            if (withChooser)
            {
                AGUtils.StartActivityWithChooser(intent.AJO, chooserTitle);
            }
            else
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
        public static void RequestPermissions(string[] permissions,
                                              Action <PermissionRequestResult[]> onRequestPermissionsResults)
        {
            if (permissions == null || permissions.Length == 0)
            {
                throw new ArgumentException("Requested permissions array must not be null or empty", "permissions");
            }

            if (onRequestPermissionsResults == null)
            {
                throw new ArgumentNullException("onRequestPermissionsResults", "Listener cannot be null");
            }

            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (IsPriorToMarshmellow())
            {
                return;
            }

            try
            {
                _onRequestPermissionsResults = onRequestPermissionsResults;
                AGActivityUtils.RequestPermissions(permissions);
            }
            catch (Exception ex)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogWarning("Could not request runtime permissions. " + ex.Message);
                }
            }
        }
Exemple #19
0
        public static void ShowStatusBar(Color color = default(Color))
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            AGUtils.RunOnUiThread(
                () =>
            {
                using (var window = AGUtils.Window)
                {
                    window.Call("clearFlags", SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                    if (AGDeviceInfo.SDK_INT >= AGDeviceInfo.VersionCodes.LOLLIPOP)
                    {
                        window.Call("setStatusBarColor", color.ToAndroidColor());
                    }
                    else if (color != default(Color))
                    {
                        Debug.LogWarning("Changing the status bar color is not supported on Android API lower than Lollipop.");
                    }
                }
            });
        }
Exemple #20
0
        public static void TakePhoto(Action <ImagePickResult> onSuccess, Action <string> onError,
                                     ImageResultSize maxSize = ImageResultSize.Original, bool shouldGenerateThumbnails = true)
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            if (onSuccess == null)
            {
                throw new ArgumentNullException("onSuccess", "Success callback cannot be null");
            }

            if (!AGPermissions.IsPermissionGranted(AGPermissions.CAMERA))
            {
                onError(AGUtils.GetPermissionErrorMessage(AGPermissions.CAMERA));
                return;
            }

            _onSuccessAction = onSuccess;
            _onCancelAction  = onError;

            AGUtils.RunOnUiThread(() => AGActivityUtils.TakePhoto(maxSize, shouldGenerateThumbnails));
        }