0

I made an app by this code:

    // Create a BroadcastReceiver for ACTION_FOUND.
private final BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if(BluetoothDevice.ACTION_FOUND.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            String str = device.getName() + "\n" + device.getAddress();

            bluFoundArrayAdapter.add(str);
        }
    }
};


public void searchBluetooth(View v) {
    // Register for broadcasts when a device is discovered.
    if(myBluetoothAdapter.isDiscovering()) {
        myBluetoothAdapter.cancelDiscovery();
    } else {
        Intent intent = new Intent(BluetoothDevice.ACTION_FOUND);
        sendBroadcast(intent);

        IntentFilter filter  = new IntentFilter(BluetoothDevice.ACTION_FOUND);
        registerReceiver(receiver, filter);

        myBluetoothAdapter.startDiscovery();

    }
}

my expect is when I press the button "search for Bluetooth device", then Bluetooth devices within range would be shown in the listview, but the App stopped when I pressed the button, and in the logout, it was these:

Whats more, I have added the 2 permissions into AndroidMenifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
user924245
  • 11
  • 3
  • maybe this would help: https://stackoverflow.com/questions/49248539/sending-non-protected-broadcast-com-motorola-motocare-intent-trigger-java-lang-t – kabayaba Dec 30 '20 at 05:43
  • I found this"W/System.err: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.bluetooth.device.action.FOUND from pid=14031, uid=10218" in logcat. – user924245 Dec 30 '20 at 10:10
  • Untile you don't write us the Log where the Exception is located, we are not able to help you so much..... – emandt Dec 30 '20 at 13:11
  • Shortened URL are frowned upon, as anything could hind behind them. – Martin Zeitler Dec 31 '20 at 01:02

0 Answers0