意图过滤器的清单不启动我的活动我的、过滤器、意图、清单

2023-09-06 18:55:42 作者:  _▄▕纯m¨|爷们 _▄▕纯m¨|娘们

我在做一个管理蓝牙设置应用程序中的一个新的应用程序。我有一个问题:我想在接下来的android的意图是由框架发送到启动我的活动:android.bluetooth.device.action.PAIRING_REQUEST

I'm doing a "new app" within the Settings app that manages Bluetooth. I have the next problem: I want my activity to be launched when the next android intent is sent by the framework: android.bluetooth.device.action.PAIRING_REQUEST

由于这一点,我在设置应用程序已将此添加到AndroidManifest.xml中:

Due to this, I added this to the AndroidManifest.xml in the Settings app:

<activity android:name=".mybt.MyBluetoohSettings">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

的一个问题是,一旦意图是由框架发送....我的应用程序没有启动!

The problems is that, once that intent is sent by the framework.... my app is not launched!

我也尝试过使用单意向过滤器(带有主,放大器; PAIRING_REQUEST意图)

I've also tried it using just a single intent-filter (with MAIN & PAIRING_REQUEST intents)

在理论上这应该工作,对不对?我究竟做错了什么?建议?

In theory this should work, right? What am I doing wrong? Suggestions?

在先进的感谢!

推荐答案

蓝牙配对请求需要由接收器(从广播接收器延长),而不是一个活动来处理。因此,您的清单应该包含的元素,在&lt;应用&GT; ,这看起来是这样的:

The Bluetooth pairing request needs to be handled by a Receiver (extended from BroadcastReceiver) rather than an Activity. Your manifest should therefore contain an element, inside <application>, that looks something like this :

    <receiver android:name=".MyReceiver">
        <intent-filter>
            <action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
        </intent-filter>
    </receiver>

和地方在你的应用程序,你就会有一个类调用MyReceiver:

And somewhere in your application, you'll have a class called MyReceiver :

public class MyReceiver extends BroadcastReceiver {

   public void onReceive(Context context, Intent intent) {

      //
      // Handle the pairing request
      //
   }
}