/// <summary> /// Called when request permissions result occured. /// </summary> /// <param name="requestCode">The request code.</param> /// <param name="permissions">The permissions.</param> /// <param name="grantResults">The grant results.</param> public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PERMISSION_REQUEST_CODE) { bool isFlashlightPermissionGranted = false; if (grantResults[1] == Permission.Granted) { isFlashlightPermissionGranted = true; } bool isVibratePermissionGranted = false; if (grantResults[2] == Permission.Granted) { isVibratePermissionGranted = true; } if (grantResults[0] == Permission.Granted) { // create fragments _barcodeScannerFragment = new BarcodeScannerFragment(this, RecognizedBarcodes, isFlashlightPermissionGranted, isVibratePermissionGranted); _historyFragment = new HistoryFragment(this); _settingsFragment = new SettingsFragment(this); _isCameraPermissionGranted = true; // show barcode scanner fragment SwitchToBarcodeScanner(null); // open camera OpenCamera(); } else { // close application Finish(); } } }
/// <summary> /// Called when the activity is starting. /// </summary> /// <param name="savedInstanceState"> /// If the activity is being re-initialized after previously being shut down then /// this <see cref="Bundle"/> contains the data it most recently supplied in /// <see cref="Android.App.Activity.OnSaveInstanceState(Android.OS.Bundle)"/>. /// Note: Otherwise it is <b>null</b>. /// </param> protected override void OnCreate(Bundle savedInstanceState) { // subscribe to the unhandled exception events AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; base.OnCreate(savedInstanceState); // add "fullscreen" window flag Window.AddFlags(WindowManagerFlags.Fullscreen); // set our view from the "main" layout resource SetContentView(Resource.Layout.main); try { // set the default values from an XML preference file PreferenceManager.SetDefaultValues(this, Resource.Xml.settings_page, false); // get preferences ISharedPreferences preferences = PreferenceManager.GetDefaultSharedPreferences(this); // get the language name string languageToLoad = preferences.GetString("list_languages", "auto"); // if language name is not auto if (languageToLoad != "auto") { // set choosen locale Locale locale = new Locale(languageToLoad); Locale.Default = locale; Configuration config = new Configuration(); config.Locale = locale; BaseContext.Resources.UpdateConfiguration(config, BaseContext.Resources.DisplayMetrics); this.SetContentView(Resource.Layout.main); } } catch { } SupportActionBar.SetHomeButtonEnabled(false); SupportActionBar.SetDisplayHomeAsUpEnabled(false); // check licence CheckLicense(); // if Android version is equal or higher than 6.0 (API 23) if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M) { if (CheckSelfPermission(Android.Manifest.Permission.Camera) != Permission.Granted || CheckSelfPermission(Android.Manifest.Permission.Flashlight) != Permission.Granted || CheckSelfPermission(Android.Manifest.Permission.Vibrate) != Permission.Granted) { RequestPermissions( new string[] { Android.Manifest.Permission.Camera, Android.Manifest.Permission.Flashlight, Android.Manifest.Permission.Vibrate }, PERMISSION_REQUEST_CODE); } else { _isCameraPermissionGranted = true; // create fragments _barcodeScannerFragment = new BarcodeScannerFragment(this, RecognizedBarcodes, true, true); _historyFragment = new HistoryFragment(this); _settingsFragment = new SettingsFragment(this); // show barcode scanner fragment SwitchToBarcodeScanner(null); } } // if Android version is less than 6.0 (API 23) else { _isCameraPermissionGranted = true; // create fragments _barcodeScannerFragment = new BarcodeScannerFragment(this, RecognizedBarcodes, true, true); _historyFragment = new HistoryFragment(this); _settingsFragment = new SettingsFragment(this); // show barcode scanner fragment SwitchToBarcodeScanner(null); } }