Android 6 bluetooth -


i upgraded android 6 , applications use bluetooth doesn't work new api version. it's same problem application on play store: bluetooth spp tools pro (good application view if bluetooth works) doesn't discovery of devices.

the problem seems in bluetooth discovery:

bluetoothadapter mbluetoothadapter = bluetoothadapter.getdefaultadapter(); mbluetoothadapter.startdiscovery() log.i("bluetooth", string.valueof(mbluetoothadapter.isdiscovering())); // return false 

my applications work android 4/5 , followed : http://developer.android.com/guide/topics/connectivity/bluetooth.html

staring android 6.0 not enough include permissions on manifest. have ask user explicitly each permission considered "dangerous". bluetoothdevice.action_found requires bluetooth , access_coarse_location permissions http://developer.android.com/reference/android/bluetooth/bluetoothdevice.html#action_found

the access_coarse_location http://developer.android.com/reference/android/manifest.permission.html#access_coarse_location "dangerous" permission , therefore have ask using requestpermission before doing actual discovery.

  public void dodiscovery() {     int haspermission = activitycompat.checkselfpermission(mainactivity.this, manifest.permission.access_coarse_location);     if (haspermission == packagemanager.permission_granted) {         continuedodiscovery();         return;     }      activitycompat.requestpermissions(mainactivity.this,             new string[]{                     android.manifest.permission.access_coarse_location},             request_coarse_location_permissions); } 

then on user answer on onrequestpermissionsresult

@override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) {     switch (requestcode) {        case request_coarse_location_permissions: {             if (grantresults.length == 1 && grantresults[0] == packagemanager.permission_granted) {                 continuedodiscovery();             } else {                 toast.maketext(this,                         getresources().getstring(r.string.permission_failure),                         toast.length_long).show();                 canceloperation();             }             return;         }     } } 

to work previous versions of android should use compatibility libraries , make calls using activitycompat


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -