0

I'm on android studio, and I have implemented a bluetooth activity that works not totally fine. I mean, when I start discovery, the scan is able to find Tv , bbox... but it doesn't find any iphone or android bluetooth although that they are discoverable..

Does anyone already had this issue ? Does it need a special permission ?

here is the permissions already set

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Thanks in advance :)

harry
  • 31
  • 6

2 Answers2

0

I found an answer at this post :

Android - Bluetooth discovery doesn't find any device

For me, it seemed that letting location on couldn't let my app discover other device .. I'am still on it. Feel free to comment :)

harry
  • 31
  • 6
0

Your permissions are correct, but when you want to discover available bluetooth devices you need location access to appear. and here's the program to go to location access on Android. call function statusCheck() if you use button/others.

private void statusCheck() {
    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();
    }
}

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Location access is required to search for devices, do you want to activate ?")
            .setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}
Aki32Dev
  • 1
  • 1