2011-12-01 95 views
1

如何將訂購的廣播發送給特定的接收方?我正在廣播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); 
     } 
    } 

回答

2

如果你知道Winamp的應用程序包,你可以使用setPackage限制意圖分辨率只有特定的軟件包。