アプリが閉じられているか、バックグラウンドで実行されているが、開いているか実行中の場合は、通知を表示しようとしています(クリックするとダイアログが表示されます)私は前景に直接ダイアログを表示したい。Appが実行中の場合はBroadcastReceiverでダイアログを表示
私はこのコードを持っている:
@Override
public void onReceive(Context context, Intent intent)
{
if (RunningHelper.isAppRunning(context, Constants.PROJECT_NAME))
{
Log.d("Running", "--------APP RUNNING");
}
else
{
Log.d("Running", "--------APP NOT RUNNING");
showNotification();
}
}
マイRunningHelper:
public static boolean isAppRunning(final Context context, final String packageName) {
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
if (procInfos != null)
{
for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
if (processInfo.processName.equals(packageName)) {
return true;
}
}
}
return false;
}
問題は、アプリケーションは常にその検出であるが、(onReceiveを実行している)、のための任意の手掛かりはそれを正しく行うに誰かをお持ちですか?ありがとう。
フォアグラウンドまたはバックグラウンドのアクティビティがfoで確認できます([https://stackoverflow.com/a/18469643/5308778] – Lucky