2015-08-09 45 views
0

在我的應用程序中,我有一個檢測onKeyDown新聞的服務。當按下此鍵時,我想關閉系統對話框。如何使用服務接收器關閉系統對話框?

這是我發現關閉系統對話框的代碼。

Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
      sendBroadcast(closeDialog); 

我怎麼能在我的服務接收文件添加此代碼,有沒有辦法在廣播接收器類重寫onWindowBackPressed()?

+0

什麼是 「服務接收器」。這是服務還是這是BroadcastReceiver? – yshahak

+0

這是一個BroadcastReceiver。 –

+0

那麼爲什麼你不把你在onReceive()回調中找到的代碼? – yshahak

回答

0

試試這個:

@Override 
public void onReceive(Context context, Intent intent) { 
    Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
    context.getApplicationContext().sendBroadcast(closeDialog); 
} 
相關問題