Android 7.0 ble scan no result

后端 未结 4 1829
悲&欢浪女
悲&欢浪女 2020-12-19 17:27

When I start ble(Bluetooth Le) scan for seconds, then stop scan. Then start, then stop... after about 5-8 Loops, the start action will be No effect ,this means no s

4条回答
  •  借酒劲吻你
    2020-12-19 18:05

    I had also this kind of problem. It is solved by enabling Location. In android, we need to enable Location for scan near by devices. So please check location is enable or not. Below code is useful. I hope it works, in my case it works good.

    LocationManager manager = (LocationManager) mainActivity.getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps(mainActivity);
    }else{ //scanning part}
    
    
    public void  buildAlertMessageNoGps(MainActivity mainActivity){
        final AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity);
        builder.setMessage("Your GPS seems to be disabled, do you want to enable it? It is required for this application.")
                .setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        mainActivity.startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), MainActivity.LOCATION_ENABLE);
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.cancel();
                        mainActivity.finishAffinity();
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    }
    

    After on location start scanning and get scanning result.

提交回复
热议问题