Android 应用 "unfortunately stop" 秒,而 运行。错误是找不到 activity 来处理意图

Android app "unfortunately stop"s while running. The error is no activity found to handle intent

我是 android 的新手。我正在尝试构建一个应用程序,使我的设备的蓝牙能够被发现。 在这些代码块中:

public void bTEnableDisable_Discoverable(){
    Intent discoverIntent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
    //discoverIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,300);
    startActivity(discoverIntent);
    Log.d(TAG,"scan mode");

    IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
    registerReceiver(mBroadcastReceiver2,intentFilter);
}

我遇到了这个错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.bluetooth.adapter.action.SCAN_MODE_CHANGED }

ACTION_SCAN_MODE_CHANGED 未被活动使用。它用于系统广播。您的 IntentFilterregisterReceiver() 正在正确使用此操作。但是,您不能将它与 IntentstartActivity() 一起使用,因为您的第一行代码试图这样做。

尝试 ACTION_REQUEST_DISCOVERABLE 启动 activity 以允许用户允许蓝牙发现。