1
我該如何實現廣播接收機&過濾器,以便它可以響應多個intents
。有多種動作的Android廣播接收機
private BroadcastReceiver myReceiver;
IntentFilter myFilter = new IntentFilter();
的onCreate():
myFilter.addAction("first");
myFilter.addAction("second");
myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// do different actions according to the intent
}
};
registerReceiver(myReceiver, myFilter);
從我的片段:
Intent i = new Intent("first"); sendBroadcast(i);
Intent i = new Intent("second"); sendBroadcast(i);
感謝
只是看在意向'intent.getAction行動() ' – tyczj