private async Task Initialize() { if (ContextCompat.CheckSelfPermission(Context, Manifest.Permission.Camera) != Permission.Granted) { ActivityCompat.RequestPermissions(Context as Activity, new[] { Manifest.Permission.Camera }, 42); return; } if (surface != null) { return; } surface = UrhoSurface.CreateSurface(Context as Activity); SetNativeControl(surface); await surface.Show <Game>(); }
// // Return the current state of the camera permissions. // private bool CheckCameraPermissions() { var permissionState = ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera); // Check if the Camera permission is already available. if (permissionState != Permission.Granted) { // Camera permission has not been granted. Log.Info(Tag, "CAMERA permission has NOT been granted."); return(false); } else { // Camera permissions are available. Log.Info(Tag, "CAMERA permission has already been granted."); return(true); } }
void RequestExternalStoragePermissions() { if (ActivityCompat.ShouldShowRequestPermissionRationale(Activity, Manifest.Permission.ReadExternalStorage)) { var rootView = Activity.FindViewById <View>(Android.Resource.Id.Content); requestPermissionHandler = delegate { ActivityCompat.RequestPermissions(Activity, REQUIRED_PERMISSIONS, Helpers.REQUEST_STORAGE); }; Snackbar.Make(rootView, Resource.String.permission_externalstorage_rationale, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, requestPermissionHandler) .Show(); } else { ActivityCompat.RequestPermissions(Activity, REQUIRED_PERMISSIONS, Helpers.REQUEST_STORAGE); } }
private void SaveDocumentInTemporaryFolder(String nameFile, byte[] bytes) { if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted) { // Save Document var directory = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; directory = Path.Combine(directory, Android.OS.Environment.DirectoryDownloads); string filePath = Path.Combine(directory, nameFile); File.WriteAllBytes(filePath, bytes); // Show document saved ShowDocumentSaved(filePath); } else { ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.WriteExternalStorage }, 1); } }
void RequestMicPermissions() { if (ActivityCompat.ShouldShowRequestPermissionRationale(MainActivity.Instance, Manifest.Permission.RecordAudio)) { Snackbar.Make(MainActivity.Instance.FindViewById(Android.Resource.Id.Content), "Microphone permissions are required for speech transcription!", Snackbar.LengthIndefinite) .SetAction("Ok", v => { ((Activity)MainActivity.Instance).RequestPermissions(permissions, RecordAudioPermissionCode); }) .Show(); } else { ActivityCompat.RequestPermissions((Activity)MainActivity.Instance, permissions, RecordAudioPermissionCode); } }
void RequestLocationPermission(int requestCode) { try { if (ActivityCompat.ShouldShowRequestPermissionRationale(CrossCurrentActivity.Current.Activity, Manifest.Permission.AccessFineLocation)) { ActivityCompat.RequestPermissions(CrossCurrentActivity.Current.Activity, new[] { Manifest.Permission.AccessFineLocation }, requestCode); } else { ActivityCompat.RequestPermissions(CrossCurrentActivity.Current.Activity, new[] { Manifest.Permission.AccessFineLocation }, requestCode); } } catch (Exception ex) { Log.Error("GPS EXCEPTION", ex.StackTrace); } }
private void permissionCheck() { if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example if the user has previously denied the permission. Log.Info("", "Displaying camera permission rationale to provide additional context."); var requiredPermissions = new String[] { Manifest.Permission.AccessFineLocation }; Snackbar.Make((View)Resource.Layout.activity_main, "Location access is required to show coffee shops nearby.", Snackbar.LengthIndefinite) .SetAction("OK", v => RequestPermissions(PermissionsLocation, RequestLocationId)) .Show(); return; } }
private void RequestPermissions() { var shouldProvideRationale = ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation); if (shouldProvideRationale) { Log.Info(TAG, "Displaying permission rationale to provide additional context."); var listener = (View.IOnClickListener) new RequestPermissionsClickListener { Activity = this }; ShowSnackbar(Resource.String.permission_rationale, Android.Resource.String.Ok, listener); } else { Log.Info(TAG, "Requesting permission"); ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, REQUEST_PERMISSIONS_REQUEST_CODE); } }
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState) { base.OnCreate(savedInstanceState, persistentState); Log.Debug(TAG, "SplashActivity.OnCreate"); // Get read/write permisions if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteExternalStorage }, 0); } if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, 0); } }
public void pedirPermissao() { if ((int)Build.VERSION.SdkInt >= 23) { string[] permissoes = { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation }; if (!verificarPermissao(permissoes)) { int code = 32; var activity = (MainActivity)Forms.Context; ActivityCompat.RequestPermissions(activity, permissoes, code); } } }
protected override void OnResume() { base.OnResume(); // ARCore requires camera permissions to operate. If we did not yet obtain runtime // permission on Android M and above, now is a good time to ask the user for it. if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.Camera) == Android.Content.PM.Permission.Granted) { showLoadingMessage(); // Note that order matters - see the note in onPause(), the reverse applies here. mSession.Resume(mDefaultConfig); mSurfaceView.OnResume(); } else { ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.Camera }, 0); } }
private void RequestCameraPermission() { Log.Warn(TAG, "Camera permission is not granted. Requesting permission"); var permissions = new string[] { Manifest.Permission.Camera }; if (!ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.Camera)) { ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); return; } Snackbar.Make(mGraphicOverlay, "Camera will be used for face detection", Snackbar.LengthIndefinite) .SetAction("Ok", (o) => { ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); }) .Show(); }
public void SurfaceCreated(ISurfaceHolder holder) { if (ActivityCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted) { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.Camera }, RequestCameraPermisionID); return; } try { cameraSource.Start(cameraPreview.Holder); } catch (InvalidOperationException) { } }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); global::Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState); Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); Xamarin.FormsMaps.Init(this, savedInstanceState); SharpnadoInitializer.Initialize(); LoadApplication(new App()); if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.RecordAudio) != Permission.Granted) { ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.RecordAudio }, 1); } }
private void RequestLocationPermission(int requestCode) { isRequestingLocationUpdates = false; if (ActivityCompat.ShouldShowRequestPermissionRationale(MainActivity.Instance, Manifest.Permission.AccessFineLocation)) { Snackbar.Make(rootLayout, "Requires Location Permissions", Snackbar.LengthIndefinite) .SetAction("Ok", delegate { ActivityCompat.RequestPermissions(MainActivity.Instance, new[] { Manifest.Permission.AccessFineLocation }, requestCode); }) .Show(); } else { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, requestCode); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); if (HasPermissions(this, RUNTIME_PERMISSIONS)) { SetupMapFragmentView(); } else { ActivityCompat.RequestPermissions(this, RUNTIME_PERMISSIONS, REQUEST_CODE_ASK_PERMISSIONS); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.MapsPage); var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map); mapFragment.GetMapAsync(this); if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, 1); } if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessCoarseLocation }, 2); } }
public bool RequestPermissions(int requestCode, params string[] permissions) { var missingPermissions = new List <string>(); foreach (var permission in permissions) { if (ContextCompat.CheckSelfPermission(this, permission) != Permission.Granted) { missingPermissions.Add(permission); } } if (missingPermissions.Any()) { ActivityCompat.RequestPermissions(this, missingPermissions.ToArray(), requestCode); return(true); } return(false); }
public void SurfaceCreated(ISurfaceHolder holder) { try { if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted) { ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, requestPermissionID); return; } mCameraSource.Start(mCameraView.Holder); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
private void RequestCameraPermission() { Log.Warn(TAG, "Camera permission is not granted. Requesting permission"); var permissions = new string[] { Manifest.Permission.Camera }; if (!ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.Camera)) { ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); return; } Snackbar.Make(_mGraphicOverlay, Resource.String.permission_camera_rationale, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, (o) => { ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); }) .Show(); }
// <summary> /// Event Name : RequestPermission /// Author : Sanket Prajapati /// Creation Date : 23 jan 2018 /// Purpose : Set Permission for Open Pdf in device /// Revision : /// </summary> private void RequestPermission() { Log.Info(StringResource.msgDebugTagActivityMain, StringResource.msgPermissionNotGrantedRequest); if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.WriteExternalStorage)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example if the user has previously denied the permission. Log.Info(StringResource.msgDebugTagActivityMain, StringResource.msgDisplayPermission); ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteExternalStorage }, 111); } else { // permission has not been granted yet. Request it directly. ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteExternalStorage }, 111); } }
async void LaunchUrho() { if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Permission.Granted) { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.Camera }, 42); return; } if (launched) { return; } launched = true; surface = UrhoSurface.CreateSurface(this); placeholder.AddView(surface); app = await surface.Show <MyApp>(new Urho.ApplicationOptions("MyData")); }
public void CallContact(string contactNumber) { var context = CrossCurrentActivity.Current.AppContext; var activity = CrossCurrentActivity.Current.Activity; if (ContextCompat.CheckSelfPermission(context, Manifest.Permission.CallPhone) == (int)Android.Content.PM.Permission.Granted) { //Has permission to call Toast.MakeText(CrossCurrentActivity.Current.AppContext, "Permission to call granted", ToastLength.Short).Show(); CallContactAfterPermissionOk(contactNumber); } else { //Has no permission to call. Display rationale MainActivity.ContactNumberMainActivity = contactNumber; //Need to pass this param, no cleaner way ActivityCompat.RequestPermissions(activity, new string[] { Manifest.Permission.CallPhone }, 88); } }
void RequestStoragePermission() { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, 1); //if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.Camera)) //{ // // Provide an additional rationale to the user if the permission was not granted // // and the user would benefit from additional context for the use of the permission. // // For example if the user has previously denied the permission. // ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, 1); //} //else //{ // // Camera permission has not been granted yet. Request it directly. // ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, 1); //} }
private void GetPermissions() { try { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.Camera, Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage, Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessMockLocation }, 0); } catch { } }
void RequestLocationPermission(int requestCode) { isRequestingLocationUpdates = false; if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation)) { Snackbar.Make(rootLayout, Resource.String.permission_location_rationale, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, delegate { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, requestCode); }) .Show(); } else { ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, requestCode); } }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); //Ask permission for read logs on emulator ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadCallLog }, 0); ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteCallLog }, 0); DependencyService.Register <CallInfoService>( ); LoadApplication(new App()); }
private static void RequestAppPermissions() { if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { return; } if (HasPermissions()) { return; } ActivityCompat.RequestPermissions(MainActivity.CurrentActivity, new string[] { Manifest.Permission.WriteCalendar, Manifest.Permission.ReadCalendar }, 1000); }
protected override void OnCreate(Bundle savedInstanceState) { if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Internet) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.Internet }, 0); } if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.RequestInstallPackages) != (int)Permission.Granted) { ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.RequestInstallPackages }, 0); } TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); }
protected override void OnCreate(Bundle savedInstanceState) { Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); base.OnCreate(savedInstanceState); _webView = FindViewById <WebView>(Resource.Id.webView1); _browserView = FindViewById <WebView>(Resource.Id.webView2); _toastInjector = new ToastInjectorWebViewClient(_browserView); _browserView.SetWebViewClient(_toastInjector); // _browserView.Settings.UserAgentString += " BeatOn_Quest/" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); _browserView.Settings.UserAgentString = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36" + " BeatOn_Quest /" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); _browserView.SetWebChromeClient(new WebChromeClient()); _browserView.Settings.JavaScriptEnabled = true; _browserView.Settings.AllowContentAccess = true; _browserView.Settings.CacheMode = CacheModes.Default; _browserView.Focusable = true; _browserView.Settings.MediaPlaybackRequiresUserGesture = false; _browserView.Settings.DomStorageEnabled = true; _browserView.Settings.DatabaseEnabled = true; _browserView.Settings.DatabasePath = "/data/data/" + _browserView.Context.PackageName + "/databases/"; _browserView.Download += _webView_Download; _toastInjector.Download += _toastInjector_Download; _webViewClient = new BeatOnWebViewClient(this, _webView); _webViewClient.JSInterface.OnBrowserGoBack += JSInterface_OnBrowserGoBack; _webViewClient.JSInterface.OnHideBrowser += JSInterface_OnHideBrowser; _webViewClient.JSInterface.OnNavigateBrowser += JSInterface_OnNavigateBrowser; _webViewClient.JSInterface.OnRefreshBrowser += JSInterface_OnRefreshBrowser; _webViewClient.JSInterface.OnShowBrowser += JSInterface_OnShowBrowser; _webViewClient.JSInterface.OnToast += JSInterface_OnToast; _webView.Settings.UserAgentString += " BeatOn_Quest/" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); if (CheckSelfPermission(Android.Manifest.Permission.WriteExternalStorage) != Android.Content.PM.Permission.Granted) { ActivityCompat.RequestPermissions(this, new String[] { Android.Manifest.Permission.WriteExternalStorage }, 1); } else { ContinueLoad(); } }