public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.layout_bluetooth_connection, container, false); view.FindViewById <Button>(Resource.Id.bc_go).Click += (sender, e) => { bool isSend = view.FindViewById <Switch>(Resource.Id.bc_switch).Checked; if (isSend) { BluetoothHelper.SendTo(socket); } else { BluetoothHelper.RecieveFrom(socket); } }; return(view); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); AndroidX.AppCompat.Widget.Toolbar toolbar = FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.AddDrawerListener(toggle); drawer.DrawerOpened += (sender, e) => { updateUsername(); }; toggle.SyncState(); NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetNavigationItemSelectedListener(this); BluetoothHelper.getPermission(BaseContext, this); ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.ReadExternalStorage }, 1); ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.WriteExternalStorage }, 1); TabaccoList.Init(() => { RaterSaved.Init(() => { if (RaterSaved.GetRater().Name == Rater.DefaultName) { ShowRaterChange(); } else { updateUsername(); ShowTabaccoHome(); } finishedInit = true; }); }); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.layout_sync_bluetooth, container, false); string possible = BluetoothHelper.isPossible(); if (possible != "") { view.FindViewById <TextView>(Resource.Id.sb_text).Text = possible; return(view); } view.FindViewById <TextView>(Resource.Id.sb_text).Text = "Dein GeräteName: " + BluetoothHelper.getDeviceName(); ListView list = view.FindViewById <ListView>(Resource.Id.sb_list); list.Adapter = new ArrayAdapter <string>(Context, Resource.Layout.sb_listitem, BluetoothHelper.getAvaiableDeviceNames()); list.TextFilterEnabled = true; list.ItemClick += (sender, e) => { BluetoothDevice device = BluetoothHelper.GetDeviceByName(((TextView)e.View).Text); if (device != null) { BluetoothHelper.GetAdapter().CancelDiscovery(); Console.WriteLine(device.GetType().ToString()); device.CreateBond(); Type t = device.GetType(); MethodInfo info = t.GetMethod("CreateRfcommSocket"); object o = info.Invoke(device, new object[] { 1 }); // Name "CreateRfcommSocketToServiceRecord" string var socket = (BluetoothSocket)o; //var socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")); socket.Connect(); BTDeviceArgs args = new BTDeviceArgs(); args.socket = socket; finished(this, args); } }; return(view); }