Пример #1
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));
            }
        }
        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);
                    }
                }
            }
        }
Пример #3
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);
            }
        }
Пример #4
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);
        }
Пример #5
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);
                }
            });
        }
Пример #6
0
        private static AndroidIntent CreateEmailIntent(string[] recipients, string subject, string body,
                                                       Texture2D attachment = null, string[] cc = null, string[] bcc = null)
        {
            var uri    = AndroidUri.Parse("mailto:");
            var intent = new AndroidIntent()
                         .SetAction(AndroidIntent.ACTION_SENDTO)
                         .SetData(uri)
                         .PutExtra(AndroidIntent.EXTRA_EMAIL, recipients)
                         .PutExtra(AndroidIntent.EXTRA_SUBJECT, subject)
                         .PutExtra(AndroidIntent.EXTRA_TEXT, body);

            if (cc != null)
            {
                intent.PutExtra(AndroidIntent.EXTRA_CC, cc);
            }
            if (bcc != null)
            {
                intent.PutExtra(AndroidIntent.EXTRA_BCC, bcc);
            }

            if (attachment != null)
            {
                var imageUri = AndroidPersistanceUtilsInternal.SaveShareImageToExternalStorage(attachment);
                intent.PutExtra(AndroidIntent.EXTRA_STREAM, imageUri);
            }

            return(intent);
        }
Пример #7
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);
            }
        }
Пример #8
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);
            }
        }
Пример #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);
        }
Пример #10
0
        static AndroidIntent CreateEmailIntent(string[] recipients, string subject, string body,
                                               Texture2D attachment = null, string[] cc = null, string[] bcc = null)
        {
            var uri    = AndroidUri.Parse("mailto:");
            var intent = new AndroidIntent()
                         .SetAction(AndroidIntent.ActionSendTo)
                         .SetData(uri)
                         .PutExtra(AndroidIntent.ExtraEmail, recipients)
                         .PutExtra(AndroidIntent.ExtraSubject, subject)
                         .PutExtra(AndroidIntent.ExtraText, body);

            if (cc != null)
            {
                intent.PutExtra(AndroidIntent.ExtraCc, cc);
            }
            if (bcc != null)
            {
                intent.PutExtra(AndroidIntent.ExtraBcc, bcc);
            }

            if (attachment != null)
            {
                var imageUri = AndroidPersistanceUtilsInternal.SaveImageToCacheDirectory(attachment);
                intent.PutExtra(AndroidIntent.ExtraStream, imageUri);
            }

            return(intent);
        }
Пример #11
0
        /// <summary>
        /// Shows the local notification. Upon click it will open the game if the game is not in foreground.
        /// </summary>
        /// <param name="title">Set the title (first row) of the notification, in a standard notification.</param>
        /// <param name="text">Set the text (second row) of the notification, in a standard notification.</param>
        /// <param name="when">Set the time that the event occurred. Notifications in the panel are sorted by this time.</param>
        /// <param name="tickerText">Set the text that is displayed in the status bar when the notification first arrives.</param>
        /// <param name="iconName">Icon drawable name. Icon must be included in the app in res/drawable folder</param>
        public static void ShowNotification(string title, string text,
                                            DateTime?when = null, string tickerText = null, string iconName = null)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var builderAJO = new AndroidJavaObject(CompatBuilderClass, AGUtils.Activity))
            {
                var intent        = new AndroidIntent(AGUtils.GetMainActivityClass());
                var pendingIntent = AndroidPendingIntent.GetActivity(intent.AJO);

                builderAJO.CallAJO("setContentTitle", title);
                builderAJO.CallAJO("setContentText", text);
                builderAJO.CallAJO("setAutoCancel", true);

                builderAJO.CallAJO("setWhen", (when ?? DateTime.Now).ToMillisSinceEpoch());

                int icon = string.IsNullOrEmpty(iconName) ? R.UnityLauncherIcon : R.GetAppDrawableId(iconName);
                builderAJO.CallAJO("setSmallIcon", icon);

                builderAJO.CallAJO("setDefaults", DEFAULT_ALL);
                builderAJO.CallAJO("setContentIntent", pendingIntent);
                //builderAJO.CallAJO("setContentInfo", "Info");
                if (!string.IsNullOrEmpty(tickerText))
                {
                    builderAJO.CallAJO("setTicker", tickerText);
                }

                AGSystemService.NotificationService.Call("notify", 1, builderAJO.CallAJO("build"));
                intent.Dispose();
                pendingIntent.Dispose();
            }
        }
Пример #12
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));
            }
        }
Пример #13
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);
            }
        }
        static AndroidIntent CreateScheduleNotificationIntent(Notification notification, int id, string tag)
        {
            var intent = new AndroidIntent(AGUtils.ClassForName(C.GoodiesNotificationManagerClassModern));

            intent.PutExtra("notification", notification.AJO);
            intent.PutExtra("id", id);
            intent.PutExtra("tag", tag);
            return(intent);
        }
        /// <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);
        }
Пример #16
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);
        }
Пример #17
0
        // API 1

        /// <summary>
        /// Check if the current device can open the specified settings screen.
        /// </summary>
        /// <returns><c>true</c> if the current device can open the specified settings screen; otherwise, <c>false</c>.</returns>
        /// <param name="action">Action.</param>
        public static bool CanOpenSettingsScreen(string action)
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            var intent = new AndroidIntent(action);

            return(intent.ResolveActivity());
        }
Пример #18
0
        public static void ShowAvailableWifiNetworks()
        {
            if (AGUtils.IsNotAndroid())
            {
                return;
            }

            using (var intent = new AndroidIntent(AndroidIntent.ActionPickWifiNetwork))
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
Пример #19
0
        public static bool UserHasTimerApp()
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            using (var intent = new AndroidIntent(ACTION_SET_TIMER))
            {
                return(intent.ResolveActivity());
            }
        }
Пример #20
0
        /// <summary>
        /// Indicates whether the device has the app installed which can place phone calls
        /// </summary>
        /// <returns><c>true</c>, if user has any phone app installed, <c>false</c> otherwise.</returns>
        public static bool UserHasPhoneApp()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            using (var i = new AndroidIntent(AndroidIntent.ACTION_DIAL))
            {
                return(i.ResolveActivity());
            }
        }
Пример #21
0
        public static bool CanShowListOfAlarms()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            using (var intent = new AndroidIntent(ACTION_SHOW_ALARMS))
            {
                return(intent.ResolveActivity());
            }
        }
Пример #22
0
        public static bool CanSetAlarm()
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            using (var intent = new AndroidIntent(ACTION_SET_ALARM))
            {
                return(intent.ResolveActivity());
            }
        }
Пример #23
0
        public static bool CanSetTimer()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }

            using (var intent = new AndroidIntent(ACTION_SET_TIMER))
            {
                return(intent.ResolveActivity());
            }
        }
Пример #24
0
        public static void ShowAllAlarms()
        {
            if (AGUtils.IsNotAndroidCheck())
            {
                return;
            }

            using (var intent = new AndroidIntent(ACTION_SHOW_ALARMS))
            {
                AGUtils.StartActivity(intent.AJO);
            }
        }
Пример #25
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 (AGUtils.IsNotAndroidCheck())
            {
                return(false);
            }
            // Dummy intent just to check if any apps can handle the intent
            var intent = new AndroidIntent(AndroidIntent.ACTION_VIEW);
            var uri    = AndroidUri.Parse(string.Format(MapUriFormat, 0, 0, DefaultMapZoomLevel));

            return(intent.SetData(uri).ResolveActivity());
        }
Пример #26
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);
        }
Пример #27
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);
            }
        }
Пример #28
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);
            }
        }
        public static bool UserHasCalendarApp()
        {
            if (AGUtils.IsNotAndroid())
            {
                return(false);
            }

            // dummy intent to resolve activity
            using (var intent = new AndroidIntent(AndroidIntent.ActionInsert).SetData(Events.CONTENT_URI))
            {
                intent.PutExtra(Events.TITLE, "dummy_title");
                intent.PutExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, (long)123);
                return(intent.ResolveActivity());
            }
        }
Пример #30
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);
            }
        }