コード例 #1
0
        void InitReceiver()
        {
            var coarseLocationPermissionGranted =
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation);
            var fineLocationPermissionGranted =
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation);

            if (coarseLocationPermissionGranted != Permission.Denied ||
                fineLocationPermissionGranted == Permission.Denied)
            {
                ActivityCompat.RequestPermissions(this, LocationPermissions, LocationPermissionsRequestCode);
            }

            //var discoverableIntent = new Intent(BluetoothAdapter.ActionRequestDiscoverable);
            //discoverableIntent.PutExtra(BluetoothAdapter.ExtraDiscoverableDuration, 300);
            //StartActivity(discoverableIntent);

            // Register for broadcasts when a device is discovered
            _receiver = new BluetoothDeviceReceiver();

            //var callback = BluetoothGattCallback


            RegisterBluetoothReceiver();

            PopulateListView();
        }
コード例 #2
0
        internal BluetoothAdapter(Android.Bluetooth.BluetoothAdapter adapter)
        {
            _adapter = adapter;
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Android.Bluetooth.BluetoothDevice.ActionNameChanged);
            _deviceReceiver = new BluetoothDeviceReceiver(this);
            Android.App.Application.Context.RegisterReceiver(_deviceReceiver, filter);
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            if (!(ContextCompat.CheckSelfPermission(this, locationPermission) == (int)Permission.Granted))
            {
                ActivityCompat.RequestPermissions(this, new String[] { locationPermission, locationfinePermission, bluetoothPermission, bluetoothadminPermission, wifiPermission, changewifiPermission }, requestPermissions);
            }

            bluetoothAdapter.Enable();

            bluetoothAdapter.StartDiscovery();

            BluetoothDeviceReceiver bluetoothDeviceReceiver = new BluetoothDeviceReceiver();

            RegisterReceiver(bluetoothDeviceReceiver, new IntentFilter(BluetoothDevice.ActionFound));

            WifiManager wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WifiService);

            wifiManager.StartScan();

            WifiReceiver wifiReceiver = new WifiReceiver();

            RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));

            /*var networks = wifiManager.ConfiguredNetworks;
             * string wifi = "";
             *
             * for (int i = 0; i < networks.Count; i++)
             * {
             *  wifi = wifi + networks[i].Ssid + "\r\n";
             *  DisplayTextWifi(wifi);
             * }*/


            /*string networkSSID = "WIFI-GUEST";
             * string networkPass = "";
             *
             * WifiConfiguration wifiConfig = new WifiConfiguration();
             * wifiConfig.Ssid = string.Format("\"{0}\"", networkSSID);
             * wifiConfig.PreSharedKey = string.Format("\"{0}\"", networkPass);
             *
             * int netId = wifiManager.AddNetwork(wifiConfig);
             * wifiManager.Disconnect();
             * wifiManager.EnableNetwork(netId, true);
             * wifiManager.Reconnect();*/
        }
コード例 #4
0
ファイル: Utiles.cs プロジェクト: cdcorrea/Syntex_repo
        public static void LeerChip(AppCompatActivity ventana, EditText control)
        {
            _receiver = new BluetoothDeviceReceiver(ventana);

            Task.Run(async() =>
            {
                Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal;
                var str = await _receiver.ReadData();

                Handler mainHandler         = new Handler(Looper.MainLooper);
                Java.Lang.Runnable runnable = new Java.Lang.Runnable(() =>
                {
                    control.Text = str;
                });
                mainHandler.Post(runnable);
            });
        }
コード例 #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Activity_BlueTooth);

            var rv = FindViewById <RecyclerView>(Resource.Id.rvBlueTooth);

            rv.SetLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.Vertical, false));
            ysAdapter = new YsBluetoothAdapter(this);
            ysAdapter.ItemClickEventArg += YsAdapter_ItemClickEventArg;
            rv.SetAdapter(ysAdapter);
            InvokeViewModel();

            _Receiver = new BluetoothDeviceReceiver();
            _Receiver.BleReceiveEvent -= Receiver_BleReceiveEvent;
            _Receiver.BleReceiveEvent += Receiver_BleReceiveEvent;
        }
コード例 #6
0
        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);

            var app = new App();

            BluetoothReceiver        = new BluetoothDeviceReceiver();
            BluetoothReceiver.Found += BluetoothReceiver_Found;;
            RegisterReceiver(BluetoothReceiver, new IntentFilter(BluetoothDevice.ActionFound));

            LoadApplication(app);
            //UnregisterReceiver(BluetoothReceiver);
        }
コード例 #7
0
ファイル: MainActivity.cs プロジェクト: msthrax/BLEApp
        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);
            LoadApplication(new App());

            //Task.Factory.StartNew(StartBle);

            androidBluetooth = new msBluetoothDroid(BluetoothAdapter.DefaultAdapter, ApplicationContext);
            androidBluetooth.Init();

            _receiver = new BluetoothDeviceReceiver();
            _receiver.SetLocalAndroidBluetooth(androidBluetooth);
            RegisterReceiver(_receiver, new IntentFilter(BluetoothDevice.ActionFound));
        }
コード例 #8
0
 private void InitBluetoothReciver()
 {
     _Receiver = new BluetoothDeviceReceiver();
     _Receiver.BleReceiveEvent += Receiver_BleReceiveEvent;
 }