intent-filter in the manifest does not launch my activity
I'm doing a "new app" within the Set开发者_如何学Ctings 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
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!
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?
Thanks in advanced!
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>
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
//
}
}
精彩评论