How to add IntentFilter in an Activity by code?
i have this activity that holds 2 intent filters and my problem is not to use this activity开发者_运维知识库 for devices 1.6 and before since i wanted them to use the native contacts.
thanks!
public class A extends Activity {
public A {
IntentFilter filter = new IntentFilter(YOUR_BROADCAST);
filter.addAction(YOUR_BROADCAST_2);
registerReceiver(mReceiver, filter);
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// code here
}
};
}
First you declare your filter - you can add multiple actions to single filter.
Then you need to register it with BroadcastReceiver
that will serve then upon arrival.
精彩评论