Requesting multiple Bluetooth permissions in Android Marshmellow -
i'm developing app connectivity connects bluetooth device sdk 23 compile with. i'm having problems requesting multiple permissions bluetooth. have done far:
@override public void onstart() { super.onstart(); if (d) log.e(tag, "++ on start ++"); if (contextcompat.checkselfpermission(mybluetoothclientactivity.this, manifest.permission.bluetooth) != packagemanager.permission_granted) { } else { activitycompat.requestpermissions(mybluetoothclientactivity.this, new string[]{manifest.permission.bluetooth, manifest.permission.bluetooth_admin}, request_enable_bt); } if (contextcompat.checkselfpermission(mybluetoothclientactivity.this, manifest.permission.bluetooth) != packagemanager.permission_granted) { } else { activitycompat.requestpermissions(mybluetoothclientactivity.this, new string[]{manifest.permission.bluetooth, manifest.permission.bluetooth_admin}, request_connect_device_insecure); } } @override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) { switch (requestcode) { case request_enable_bt: { // if request cancelled, result arrays empty. if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { // permission granted, yay! intent enableintent = new intent( bluetoothadapter.action_request_enable); startactivityforresult(enableintent, request_enable_bt); } else { // permission denied, boo! disable // functionality depends on permission. if (commondata.mchatservice == null) setupchat(); toast.maketext(mybluetoothclientactivity.this, "permission denied bluetooth", toast.length_short).show(); } return; } case request_connect_device_insecure: { // if request cancelled, result arrays empty. if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { // permission granted, yay! intent enableintent = new intent( bluetoothadapter.action_request_enable); startactivityforresult(enableintent, request_connect_device_insecure); } else { // permission denied, boo! disable // functionality depends on permission. if (commondata.mchatservice == null) setupchat(); toast.maketext(mybluetoothclientactivity.this, "permission denied bluetooth", toast.length_short).show(); } return; } // other 'case' lines check other // permissions app might request } }
although i'm able dialogue box requesting enabling bluetooth, don't second permission, i.e. connect device. in logcat, get:
01-01 06:41:24.334 25473-25473 e/bluetoothchat: ++ on start ++ 01-01 06:41:24.344 25473-25473 w/activity: can reqeust 1 set of permissions @ time
and since i'm not able connect device, stuck here. , code works fine on android version lollipop, causes problem on marshmallow version.
bluetooth
, bluetooth_admin
normal permissions , therefore automatically granted. permissions in table of dangerous permissions need requested @ runtime.
however, mentioned in android 6.0 changes: access hardware identifier:
to access hardware identifiers of nearby external devices via bluetooth , wi-fi scans, app must have access_fine_location or access_coarse_location permissions:
if you're using of methods, you'll need request @ least access_coarse_location
@ runtime (as is dangerous permission).
Comments
Post a Comment