【发布时间】:2011-12-01 19:14:02
【问题描述】:
如何将有序广播发送给特定的接收者?我正在广播 ACTION_MEDIA_BUTTON 并且只希望特定的应用程序(例如 Winamp)接收它。我不想让潘多拉偷走它。有没有办法明确定义接收者是谁?
void sendBroadcast() {
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
synchronized (this) {
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, theKeyEvent));
ctx.sendOrderedBroadcast(i, null);
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, theKeyEvent));
ctx.sendOrderedBroadcast(i, null);
}
}
【问题讨论】:
标签: java android broadcastreceiver android-intent intentfilter