onMessage()
GCM から受信したときに、アプリケーションが開いていて、現在ユーザーに表示されているかどうかを確認する方法を知りたいです。最初は独自の を使用していましboolean isVisible
たが、アプリが開いていない場合、そのフラグにアクセスするために使用するオブジェクトは であるため、これは信頼できないことに気付きましたnull
。これ自体を使用してアプリが開いているかどうかを確認できますが、少し面倒です。アプリケーションが現在開いているかどうか、およびユーザーがアプリを表示しているかどうかを何らかの方法でチェックするシステム レベルから Android に方法はありますか? ユーザーが最近「ホーム」ボタンを押してアプリをバックグラウンドに送信したため、アプリが技術的には実行されていても、表示されていない可能性があることに注意してください。
@Override
protected void onMessage(Context arg0, Intent arg1) {
String turn = intent.getExtras().getString("turn");
if (turn.equals("yours"){
if (/*app is open*/){ <------------------ what can go here?
// dont generate a notification
// display something in the game instead
}
else{
// generate notification telling player its their turn
}
}
}