protected override void OnCreate(Bundle savedInstanceState) { Instance = this; //这里设置TabbedPage选中颜色 TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; //初始化UITest AppCenter.Start("6be9c596-5920-47cc-bac1-cd2a5b3709b5", typeof(Analytics), typeof(Crashes)); //初始化弹窗 Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); //初始化takephoto CrossCurrentActivity.Current.Init(this, savedInstanceState); //初始化蓝牙 //BluetoothLowEnergyAdapter.InitActivity( this ); IBluetoothLowEnergyAdapter bleAdapter = null; BluetoothLowEnergyAdapter.Init(this); bleAdapter = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App(bleAdapter)); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); BluetoothLowEnergyAdapter.Init(this); Xamarin.Forms.Forms.Init(this, bundle); var bluetooth = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); LoadApplication(new App(bluetooth)); }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, savedInstanceState); BluetoothLowEnergyAdapter.Init(this); var ble = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); LoadApplication(new App(ble)); }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); if ((int)Build.VERSION.SdkInt >= 23) { string[] permissions = { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation }; if (CheckSelfPermission(permissions[0]) != (int)Permission.Granted || CheckSelfPermission(permissions[1]) != (int)Permission.Granted) { using (var builder = new AlertDialog.Builder(this)) { builder.SetMessage("Often android OEMs bundle bluetooth functionality with location, bluetooth doesn't work without it. Your location is never tracked."); builder.SetPositiveButton("OK", OkAction); var disclaimer = builder.Create(); disclaimer.Show(); } void OkAction(object sender, DialogClickEventArgs e) { ActivityCompat.RequestPermissions(this, permissions, 0); } } } //Set UI to Full Screen SetImmersiveUI(); //This line is required to Enable/Disable Bluetooth try { BluetoothLowEnergyAdapter.Init(this); } catch (Exception ex) { Log.Debug("RoverControl", ex.Message); } //Get Bluetooth adapter var bluetoothAdapter = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); //Initialize ACR UserDialogs UserDialogs.Init(this); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App(bluetoothAdapter)); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); BluetoothLowEnergyAdapter.Init(this); UserDialogs.Init(this); Forms.Init(this, bundle); LoadApplication( new FormsApp(BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext), UserDialogs.Instance)); }
protected override void OnMAMCreate(Bundle bundle) { //TabLayoutResource = Resource.Layout.Tabbar; // ToolbarResource = Resource.Layout.Toolbar; base.OnMAMCreate(bundle); UserDialogs.Init(this); global::Xamarin.Forms.Forms.Init(this, bundle); try { // If you want to enable/disable the Bluetooth adapter from code, you must call this. BluetoothLowEnergyAdapter.Init(this); }catch (Exception e) { Utils.Print(e.StackTrace); } // Obtain the bluetooth adapter so we can pass it into our (shared-code) Xamarin Forms app. There are // additional Obtain() methods on BluetoothLowEnergyAdapter if you have more specific needs (e.g. if you // need to support devices with multiple Bluetooth adapters) var bluetooth = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); if (Xamarin.Forms.Device.Idiom == TargetIdiom.Phone) { RequestedOrientation = ScreenOrientation.Portrait; } else { RequestedOrientation = ScreenOrientation.Landscape; } //CrossCurrentActivity.Current.Init(this, bundle); var context = Android.App.Application.Context; var info = context.PackageManager.GetPackageInfo(context.PackageName, 0); string value = info.VersionName.ToString(); // Check if FTP settings is in securestorage GenericUtilsClass.CheckFTPDownload(); LoadApplication(new FormsApp(bluetooth, UserDialogs.Instance, value)); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); UserDialogs.Init(this); Forms.Init(this, bundle); // If you want to enable/disable the Bluetooth adapter from code, you must call this. BluetoothLowEnergyAdapter.Init(this); // Obtain the bluetooth adapter so we can pass it into our (shared-code) Xamarin Forms app. There are // additional Obtain() methods on BluetoothLowEnergyAdapter if you have more specific needs (e.g. if you // need to support devices with multiple Bluetooth adapters) var bluetooth = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); LoadApplication(new FormsApp(bluetooth, UserDialogs.Instance)); }
protected override void OnMAMCreate(Bundle bundle) { //TabLayoutResource = Resource.Layout.Tabbar; // ToolbarResource = Resource.Layout.Toolbar; base.OnMAMCreate(bundle); UserDialogs.Init(this); global::Xamarin.Forms.Forms.Init(this, bundle); Xamarin.Essentials.Platform.Init(this, bundle); try { // If you want to enable/disable the Bluetooth adapter from code, you must call this. BluetoothLowEnergyAdapter.Init(this); } catch (Exception e) { Utils.Print(e.StackTrace); } // Obtain the bluetooth adapter so we can pass it into our (shared-code) Xamarin Forms app. There are // additional Obtain() methods on BluetoothLowEnergyAdapter if you have more specific needs (e.g. if you // need to support devices with multiple Bluetooth adapters) var bluetooth = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext); if (Xamarin.Forms.Device.Idiom == TargetIdiom.Phone) { RequestedOrientation = ScreenOrientation.Portrait; } else { RequestedOrientation = ScreenOrientation.Landscape; } // CrossCurrentActivity.Current.Init ( this, bundle ); var data = Intent.Data; // check if this intent is started via custom scheme link if (data != null) { if (data.Scheme == "aclara-mtu-programmer") { //accessCodeTextbox.Text = data.Host; } } // Set our view from the "main" layout resource //SetContentView(Resource.Layout.SplashScreen); Context context = Android.App.Application.Context; PackageInfo info = context.PackageManager.GetPackageInfo(context.PackageName, 0); string appversion = info.VersionName + " ( " + info.VersionCode + " )"; FormsApp app = new FormsApp(bluetooth, UserDialogs.Instance, appversion); LoadApplication(app); app.HandleUrl(new System.Uri(data.ToString()), bluetooth); }
// Public methods public async Task <bool> Initialize(Activity activity, Context context, BLECommandsParser.cmdTableDel_t action) { bool ret = false; try { g_activity = activity; g_context = context; // Initialize bluetooth adapter BluetoothLowEnergyAdapter.Init(activity); // Obtain bluetooth adapter handler g_BLEAdapterObj = BluetoothLowEnergyAdapter.ObtainDefaultAdapter(context); // Enable BLE adapter in case it is disabled. Close application if user denie if (g_BLEAdapterObj.AdapterCanBeEnabled && g_BLEAdapterObj.CurrentState.IsDisabledOrDisabling()) { await g_BLEAdapterObj.EnableAdapter(); if (true == g_BLEAdapterObj.CurrentState.IsDisabledOrDisabling()) { Library.CloseApplication(activity); } } // Suscribe to receive BLE adapter state changes g_BLEAdapterObj_stateChangeObserver = OnBLEAdapter_StateChange; g_BLEAdapterObj.CurrentState.Subscribe(Observer.Create <EnabledDisabledState>(g_BLEAdapterObj_stateChangeObserver, null, null)); // Suscribe to receive Location adapter state changes g_LocationAdapterStateChangeObserver = new OnLocationAdapterStateChange(); activity.RegisterReceiver(g_LocationAdapterStateChangeObserver, new IntentFilter(LocationManager.ProvidersChangedAction)); // Enable location service permissions. Needed to make BLE device scan Permission permissionCheck = ContextCompat.CheckSelfPermission(activity, Manifest.Permission.AccessFineLocation); if (permissionCheck != Permission.Granted) { if (true == Android.Support.V4.App.ActivityCompat.ShouldShowRequestPermissionRationale(activity, Manifest.Permission.AccessFineLocation)) { Toast.MakeText(activity, "The permission to get BLE location data is required", ToastLength.Short).Show(); } else { activity.RequestPermissions(new String[] { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessCoarseLocation }, 1); } } else { Toast.MakeText(activity, "Location permissions already granted", ToastLength.Short).Show(); } // Get Location Manager and check for GPS & Network location services. Ask user to enable them if needed LocationManager lm = (LocationManager)context.GetSystemService(Context.LocationService); if (!lm.IsProviderEnabled(LocationManager.GpsProvider) || !lm.IsProviderEnabled(LocationManager.NetworkProvider)) { EventHandler <DialogClickEventArgs> ButtonClickCb = OnLocationMsgButtonClick; // Build the alert dialog Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(activity); builder.SetTitle("Location Services Not Active"); builder.SetMessage("Please enable Location Services and GPS"); builder.SetPositiveButton("OK", ButtonClickCb); Dialog alertDialog = builder.Create(); alertDialog.SetCanceledOnTouchOutside(false); alertDialog.Show(); } // Initialize BLE Commands Parser g_BLECommandsParserObj = new BLECommandsParser(); Library.cmdTable += action; ret = true; } catch (Exception) { } return(ret); }