protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here

            global::Android.Net.Uri uri_android = Intent.Data;

#if DEBUG
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("ActivityCustomUrlSchemeInterceptor.OnCreate()");
            sb.Append("     uri_android = ").AppendLine(uri_android.ToString());
            System.Diagnostics.Debug.WriteLine(sb.ToString());
#endif

            // Convert iOS NSUrl to C#/netxf/BCL System.Uri - common API
            Uri uri_netfx = new Uri(uri_android.ToString());

            if (AuthenticationService.TaskCompletionSource != null)
            {
                AuthenticationService.TaskCompletionSource.SetResult(uri_android.ToString());
            }

            // load redirect_url Page
            //WebAuthenticator wa =
            //    (WebAuthenticator)AuthenticatorPageRenderer.Authenticator;

            //wa?.OnPageLoading(uri_netfx);


            this.Finish();

            return;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            VerifyIntent(this.Intent);

            global::Android.Net.Uri uri_android = Intent.Data;

            #if DEBUG
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("ActivityCustomUrlSchemeInterceptor.OnCreate()");
            sb.Append("     uri_android = ").AppendLine(uri_android.ToString());
            System.Diagnostics.Debug.WriteLine(sb.ToString());
            #endif

            // Convert Android.Net.Uri to C#/netxf/BCL System.Uri - common API
            Uri uri_netfx = new Uri(uri_android.ToString());

            // load redirect_url Page
            MainActivity.Auth2?.OnPageLoading(uri_netfx);
            MainActivity.Auth1?.OnPageLoading(uri_netfx);

            this.Finish();

            return;
        }
Example #3
0
        void GetMetaData(global::Android.Net.Uri uri, IDictionary <string, string> headers)
        {
            Task.Run(() =>
            {
                var retriever = new MediaMetadataRetriever();

                if (uri.Scheme != null && uri.Scheme.StartsWith("http") && headers != null)
                {
                    try
                    {
                        retriever.SetDataSource(uri.ToString(), headers);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);
                    }
                }
                else
                {
                    retriever.SetDataSource(Context, uri);
                }

                ExtractMetadata(retriever);

                MetadataRetrieved?.Invoke(this, EventArgs.Empty);
            });
        }
Example #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                global::Android.Net.Uri uri_android = Intent.Data;

                // Convert Android.Net.Url to C#/netxf/BCL System.Uri - common API
                Uri uri_netfx = new Uri(uri_android.ToString());

                // load redirect_url Page for parsing
                AuthenticationState.Authenticator.OnPageLoading(uri_netfx);

                this.Finish();

                return;
            }
            catch (Exception e)
            {
                // Log if Intent is null or Intent.Data is null or Intent.Data
                string error = Intent == null ?
                               "Intent was null" :
                               (Intent.Data == null ? "Intent.Data was null" : "Intent.Data: " + Intent.Data.ToString());

                LogUtils.LogException(Enums.LogSeverity.WARNING, e, nameof(AuthUrlSchemeInterceptorActivity) + " " + nameof(OnCreate) + " error when redirectin to app after ID Porten validation", error);

                // Redirect and hit OnAuthError
                AuthenticationState.Authenticator.OnPageLoading(new Uri("no.fhi.smittestopp:/oauth2redirect"));

                this.Finish();

                return;
            }
        }
Example #5
0
        protected override async void OnActivityResult(int requestCode, [GeneratedEnum] global::Android.App.Result resultCode, Intent data)
        {
            bool success = resultCode == Result.Ok;

            if (requestCode == PhotoRequestCode && success)
            {
                if (previousFileUri != null && !previousFileUri.ToString().StartsWith("upload"))
                {
                    try
                    {
                        await ImageService.Instance.LoadFile(previousFileUri.Path).InvalidateAsync(FFImageLoading.Cache.CacheType.All);

                        if (File.Exists(previousFileUri.Path))
                        {
                            File.Delete(previousFileUri.Path);
                        }
                        previousFileUri = null;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("WHY: " + e.Message);
                    }
                }

                selectedImage = await AndroidUtils.OnImagePickerResult(resultCode, data, outputFileUri, this, finalImagePath, 1920, 1080);

                if (selectedImage != null)
                {
                    ImageService.Instance.LoadFile(selectedImage.Path).Transform(new CircleTransformation()).Into(imageView);
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            /*base.OnCreate(savedInstanceState);
             *
             * // Convert Android.Net.Url to Uri
             * var uri = new Uri(Intent.Data.ToString());
             *
             * // Load redirectUrl page
             * AuthenticationState.Authenticator.OnPageLoading(uri);
             *
             * Finish();*/
            base.OnCreate(savedInstanceState);
            global::Android.Net.Uri uri_android = Intent.Data;

            Uri uri_netfx = new Uri(uri_android.ToString());

            // load redirect_url Page
            AuthenticationState.Authenticator.OnPageLoading(uri_netfx);

            var intent = new Intent(this, typeof(MainActivity));

            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);

            this.Finish();

            return;
        }
Example #7
0
        private void SaveOutput(Bitmap croppedImage)
        {
            if (_saveUri != null)
            {
                try {
                    using (var outputStream = ContentResolver.OpenOutputStream(_saveUri))
                    {
                        if (outputStream != null)
                        {
                            croppedImage.Compress(_outputFormat, 75, outputStream);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(GetType().Name, ex.Message + "\n" + ex.StackTrace);
                }

                var extras = new Bundle();
                SetResult(Result.Ok, new Intent(_saveUri.ToString()).PutExtras(extras));
            }
            else
            {
                Log.Error(GetType().Name, "not defined image url");
            }

            croppedImage.Recycle();
            Finish();
        }
Example #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            global::Android.Net.Uri uri_android = Intent.Data;

            Uri uri_netfx = new Uri(uri_android.ToString());

            //new Task(() =>
            //{
            //	StartActivity(new Intent(Application.Context, typeof(MainActivity)));
            //}).Start();

            // load redirect_url Page
            AuthenticationState.Authenticator.OnPageLoading(uri_netfx);

            var intent = new Intent(this, typeof(MainActivity));

            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);

            this.Finish();

            return;
        }
Example #9
0
        private void ListenBtn_Click(object sender, EventArgs e)
        {
            if (player.IsPlaying)
            {
                player.Stop();
                player.Reset();
                listenBtn.Text = Resources.GetString(Resource.String.ListenBtn);
            }
            else
            {
                player.SetDataSource(outputFileUri.ToString().StartsWith("upload")
                    ? ServerUtils.GetUploadUrl(outputFileUri.ToString())
                    : outputFileUri.Path);

                player.Prepare();
                player.Start();
                listenBtn.Text = Resources.GetString(Resource.String.StopBtn);
            }
        }
        public override void OnChange(bool selfChange, global::Android.Net.Uri uri)
        {
            try
            {
                // for some reason, we get multiple calls to OnChange for the same outgoing text. ignore repeats.
                if (_mostRecentlyObservedSmsURI != null && uri.ToString() == _mostRecentlyObservedSmsURI)
                {
                    return;
                }

                SmsDatum datum = null;

                // process MMS:  https://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android
                bool isMMS = uri.ToString().StartsWith("content://sms/raw") || uri.ToString().StartsWith("content://mms-sms");
                if (isMMS)
                {
                    datum = GetMostRecentMMS();
                }
                else
                {
                    datum = GetSms(uri);
                }

                if (!string.IsNullOrWhiteSpace(datum?.Message))
                {
                    _outgoingSmsCallback?.Invoke(datum);

                    if (isMMS)
                    {
                        _mostRecentMmsTimestamp = datum.Timestamp;
                    }
                    else
                    {
                        _mostRecentlyObservedSmsURI = uri.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                // something is probably wrong with our implementation. each manufacturer does things a bit different.
                SensusServiceHelper.Get().Logger.Log("Exception in " + nameof(OnChange) + ":  " + ex.Message, LoggingLevel.Normal, GetType());
            }
        }
Example #11
0
        public override void OnChange(bool selfChange, global::Android.Net.Uri uri)
        {
            // for some reason, we get multiple calls to OnChange for the same outgoing text. ignore repeats.
            if (_mostRecentlyObservedSmsURI != null && uri.ToString() == _mostRecentlyObservedSmsURI)
            {
                return;
            }

            ICursor cursor = _context.ContentResolver.Query(uri, null, null, null, null);

            if (cursor.MoveToNext())
            {
                string protocol = cursor.GetString(cursor.GetColumnIndex("protocol"));
                int    type     = cursor.GetInt(cursor.GetColumnIndex("type"));

                int sentMessageType;

                #if __ANDROID_19__
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
                {
                    sentMessageType = (int)SmsMessageType.Sent;  // API level 19
                }
                else
                #endif
                sentMessageType = 2;

                if (protocol != null || type != sentMessageType)
                {
                    return;
                }

                string         to             = cursor.GetString(cursor.GetColumnIndex("address"));
                long           unixTimeMS     = cursor.GetLong(cursor.GetColumnIndex("date"));
                DateTimeOffset dotNetDateTime = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan()).AddMilliseconds(unixTimeMS);
                string         message        = cursor.GetString(cursor.GetColumnIndex("body"));
                cursor.Close();

                _outgoingSMS(new SmsDatum(dotNetDateTime, null, to, message));

                _mostRecentlyObservedSmsURI = uri.ToString();
            }
        }
        private void ShowImage()
        {
            if (selectedImage == null)
            {
                return;
            }

            if (selectedImage.ToString().StartsWith("upload"))
            {
                ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(selectedImage.ToString()))
                .Transform(new CircleTransformation()).Into(chosenImageView);
            }
            else
            {
                ImageService.Instance.LoadFile(selectedImage.Path)
                .Transform(new CircleTransformation()).Into(chosenImageView);
            }

            chosenLayout.Visibility = global::Android.Views.ViewStates.Visible;
        }
Example #13
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            global::Android.Net.Uri uri_android = Intent.Data;

            if (await OidcClient.InterceptLoginCallbackAsync(new Uri(uri_android.ToString())))
            {
                this.Finish();
            }

            return;
        }
Example #14
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            global::Android.Net.Uri uri_android = Intent.Data;

            if (OidcClient.CaptureRedirectUrl(new Uri(uri_android.ToString())))
            {
                this.Finish();
            }

            return;
        }
        protected void ShowLink(int id, global::Android.Net.Uri uri)
        {
            var v = FindViewById <TextView>(id);

            if (uri == null)
            {
                v.SetText("", TextView.BufferType.Normal);
                return;
            }
            v.SetText(uri.ToString(), TextView.BufferType.Normal);
            v.MovementMethod = LinkMovementMethod.Instance;
        }
Example #16
0
        private void OpenIntentAsync(Intent intent)
        {
            new Thread(() =>
            {
                // open page to view protocol if a protocol was passed to us
                if (intent.Data != null)
                {
                    global::Android.Net.Uri dataURI = intent.Data;

                    try
                    {
                        if (intent.Scheme == "http" || intent.Scheme == "https")
                        {
                            Protocol.DisplayFromWebUriAsync(new Uri(dataURI.ToString()));
                        }
                        else if (intent.Scheme == "content" || intent.Scheme == "file")
                        {
                            byte[] bytes = null;

                            try
                            {
                                MemoryStream memoryStream = new MemoryStream();
                                Stream inputStream        = ContentResolver.OpenInputStream(dataURI);
                                inputStream.CopyTo(memoryStream);
                                inputStream.Close();
                                bytes = memoryStream.ToArray();
                            }
                            catch (Exception ex)
                            {
                                SensusServiceHelper.Get().Logger.Log("Failed to read bytes from local file URI \"" + dataURI + "\":  " + ex.Message, LoggingLevel.Normal, GetType());
                            }

                            if (bytes != null)
                            {
                                Protocol.DisplayFromBytesAsync(bytes);
                            }
                        }
                        else
                        {
                            SensusServiceHelper.Get().Logger.Log("Sensus didn't know what to do with URI \"" + dataURI + "\".", LoggingLevel.Normal, GetType());
                        }
                    }
                    catch (Exception ex)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            new AlertDialog.Builder(this).SetTitle("Failed to get protocol").SetMessage(ex.Message).Show();
                        });
                    }
                }
            }).Start();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            VerifyIntent(this.Intent);
            global::Android.Net.Uri uri_android = Intent.Data;
            // Convert Android.Net.Uri to C#/netxf/BCL System.Uri - common API
            Uri uri_netfx = new Uri(uri_android.ToString());

            // Load redirectUrl page
            AuthenticationState.Authenticator.OnPageLoading(uri_netfx);
            this.Finish();
            return;
        }
Example #18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            global::Android.Net.Uri androidUri = Intent.Data;
            var uri = new Uri(androidUri.ToString());
            var log = DependencyService.Get <ILog>();

            log.Debug($"OnCreate: Uri={uri}");
            Authorization.GetAuthorizingAppDelegate().ActivateApp();
            var authCallbackHandler = DependencyService.Get <IAuthCallbackHandler>();

            authCallbackHandler?.HandleUrlCallback(uri);
            Finish();
        }
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        global::Android.Net.Uri uri_android = Intent.Data;
        // Convert Android.Net.Url to Uri
        var uri = new Uri(uri_android.ToString());
        // Close browser
        var intent = new Intent(this, typeof(MainActivity));

        //intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
        StartActivity(intent);
        // Load redirectUrl page
        OAuthAuthenticatorHelper.AuthenticationState.OnPageLoading(uri);
        this.Finish();
    }
        protected override void OnNewIntent(Intent intent)
        {
            VerifyIntent(intent);

            global::Android.Net.Uri uri_android = intent.Data;

#if DEBUG
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("ActivityCustomUrlSchemeInterceptor.OnNewIntent(Intent intent)");
            sb.Append("     uri_android = ").AppendLine(uri_android.ToString());
            System.Diagnostics.Debug.WriteLine(sb.ToString());
#endif

            return;
        }
Example #21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            global::Android.Net.Uri uri_android = Intent.Data;

#if DEBUG
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("GoogleAuthInterceptorActivity.OnCreate()");
            sb.Append("     uri_android = ").AppendLine(uri_android.ToString());
            System.Diagnostics.Debug.WriteLine(sb.ToString());
#endif

            var uri = new Uri(uri_android.ToString());

            // Send the URI to the Authenticator for continuation
            AuthenticationState.Authenticator?.OnPageLoading(uri);

            var intent = new Intent(this, typeof(MainActivity));
            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);

            Finish();
        }
Example #22
0
        private void GetMetaData(global::Android.Net.Uri uri, IDictionary <string, string> headers)
        {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();

            if (uri.Scheme.StartsWith("http"))
            {
                retriever.SetDataSource(uri.ToString(), headers);
            }
            else
            {
                retriever.SetDataSource(Context, uri);
            }

            ExtractMetadata(retriever);
        }
Example #23
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CreateNewActivity);

            titleInput     = FindViewById <EditText>(Resource.Id.titleInput);
            descInput      = FindViewById <EditText>(Resource.Id.descInput);
            imageView      = FindViewById <ImageViewAsync>(Resource.Id.activityIcon);
            continueButton = FindViewById <Button>(Resource.Id.continueBtn);

            imageView.Click      += ImageView_Click;
            continueButton.Click += ContinueButton_Click;

#if DEBUG
            titleInput.Text = "DEBUG TITLE";
            descInput.Text  = "DEBUG DESCRIPTION";
#endif

            string jsonData = Intent.GetStringExtra("JSON") ?? "";
            newActivity = JsonConvert.DeserializeObject <LearningActivity>(jsonData, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            // load given details in if available
            if (newActivity != null)
            {
                editing         = true;
                titleInput.Text = newActivity.Name;
                descInput.Text  = newActivity.Description;

                if (!string.IsNullOrWhiteSpace(newActivity.ImageUrl))
                {
                    if (newActivity.ImageUrl.StartsWith("upload"))
                    {
                        selectedImage = global::Android.Net.Uri.Parse(newActivity.ImageUrl);
                        ImageService.Instance.LoadUrl(ServerUtils.GetUploadUrl(selectedImage.ToString()))
                        .Transform(new CircleTransformation())
                        .Into(imageView);
                    }
                    else
                    {
                        selectedImage = global::Android.Net.Uri.FromFile(new Java.IO.File(newActivity.ImageUrl));
                        ImageService.Instance.LoadFile(selectedImage.Path).Transform(new CircleTransformation()).Into(imageView);
                    }
                }
            }
        }
Example #24
0
        public static void OnCreate(Activity activity, Intent intent, bool finish = true)
        {
            global::Android.Net.Uri androidUri = intent.Data;
            var uri = new Uri(androidUri.ToString());
            var log = DependencyService.Get <ILog>();

            log.Debug($"OnCreate: Uri={uri}");
            Authorization.GetAuthorizingAppDelegate().ActivateApp();
            var authCallbackHandler = DependencyService.Get <IAuthCallbackHandler>();

            authCallbackHandler?.HandleUrlCallback(uri);
            if (finish)
            {
                activity.Finish();
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            global::Android.Net.Uri uri_android = Intent.Data;

            if (uri_android != null)
            {
                // Convert Android.Net.Url to C#/netxf/BCL System.Uri - common API
                Uri uri_netfx = new Uri(uri_android.ToString());

                // load redirect_url Page for parsing
                MobileServiceUIAuthentication.CurrentAuthenticator?.OnPageLoading(uri_netfx);
            }

            this.Finish();
        }
Example #26
0
        protected async Task SetMetadata(global::Android.Net.Uri uri, IDictionary <string, string>?headers)
        {
            var retriever = new MediaMetadataRetriever();

            if (uri.Scheme != null && uri.Scheme.StartsWith(Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase))
            {
                await retriever.SetDataSourceAsync(uri.ToString(), headers ?? new Dictionary <string, string>());
            }
            else
            {
                await retriever.SetDataSourceAsync(Context, uri);
            }

            ExtractMetadata(retriever);

            MetadataRetrieved?.Invoke(this, EventArgs.Empty);
        }
        public override void SetVideoURI(global::Android.Net.Uri uri)
        {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();

            if (uri.Scheme.StartsWith("http"))
            {
                retriever.SetDataSource(uri.ToString(), new Dictionary <string, string>());
            }
            else
            {
                retriever.SetDataSource(Context, uri);
            }

            ExtractMetadata(retriever);

            base.SetVideoURI(uri);
        }
Example #28
0
        static string GetFileName(global::Android.Net.Uri contentUri)
        {
            // resolve file name by querying content provider for display name
            var filename = QueryContentResolverColumn(contentUri, MediaStore.MediaColumns.DisplayName);

            if (string.IsNullOrWhiteSpace(filename))
            {
                filename = Path.GetFileName(WebUtility.UrlDecode(contentUri.ToString()));
            }

            if (!Path.HasExtension(filename))
            {
                filename = filename.TrimEnd('.') + '.' + GetFileExtensionFromUri(contentUri);
            }

            return(filename);
        }
Example #29
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            global::Android.Net.Uri uriAndroid = Intent.Data;

            Uri uriNetfx = new Uri(uriAndroid.ToString());

            AuthenticationState.Authenticator.OnPageLoading(uriNetfx);

            var intent = new Intent(this, typeof(MainActivity));

            intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
            StartActivity(intent);

            this.Finish();

            return;
        }
Example #30
0
        protected void GetMetaData(global::Android.Net.Uri uri, IDictionary <string, string> headers)
        {
            Task.Run(() =>
            {
                var retriever = new MediaMetadataRetriever();

                if (uri.Scheme != null && uri.Scheme.StartsWith("http"))
                {
                    retriever.SetDataSource(uri.ToString(), headers ?? new Dictionary <string, string>());
                }
                else
                {
                    retriever.SetDataSource(Context, uri);
                }

                ExtractMetadata(retriever);

                MetadataRetrieved?.Invoke(this, EventArgs.Empty);
            });
        }