Android 当应用程序已打开且通知已发出时,如何在对话框中显示推送通知?

Android 当应用程序已打开且通知已发出时,如何在对话框中显示推送通知?,android,push-notification,Android,Push Notification,我只想在收到通知并且应用程序已经打开时显示对话框。 如果应用程序像divyabhaskar Android应用程序一样打开,我不想在通知栏上显示通知。当通知到来时,请编写以下代码 ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am

我只想在收到通知并且应用程序已经打开时显示对话框。
如果应用程序像divyabhaskar Android应用程序一样打开,我不想在通知栏上显示通知。当通知到来时,请编写以下代码

 ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningTaskInfo> taskInfo = am
                    .getRunningTasks(1);
            Log.d("current task :", "CURRENT Activity ::"
                    + taskInfo.get(0).topActivity.getClass().getSimpleName());
             ComponentName componentInfo = taskInfo.get(0).topActivity;
                        className = componentInfo.getClassName();
                        Log.v("", "class Name-" + className);

                        if (extras != null) {
                            if (componentInfo.getPackageName().equalsIgnoreCase(
                                    getPackageName())) {


                                    Log.v("", "inside app-");

                                    Intent broadcast = new Intent(ApplicationConstants.MY_BROADCAST);
                                    broadcast.putExtra(ApplicationConstants.BOOKING_ID, bookingId);
                                    broadcast.putExtra(ApplicationConstants.NOTIFICATION_TYPE, type);
                                    broadcast.putExtra(ApplicationConstants.MESSAGE, message);
                                    broadcast.putExtra(ApplicationConstants.CLASS_NAME, className);
                        LocalBroadcastManager.getInstance(this).sendBroadcast(
                                broadcast);
                        Log.v("", "Sending broadcast....");
                    } else {
                        sendNotification(extras);
                   }
接收广播

private BroadcastReceiver receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ApplicationConstants.MY_BROADCAST)) {
            //Log.v("", "inside on receiver-");

            showDialog(intent.getStringExtra(ApplicationConstants.MESSAGE));


        }
    }
};
在onStop方法中注销广播

 @Override
protected void onStop() {
    super.onStop();
    if (receiver != null) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
    }
}            

请显示一些代码,说明您当前如何在应用程序中接收推送通知。
 @Override
protected void onStop() {
    super.onStop();
    if (receiver != null) {
        LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
    }
}