点击通知没有启动计划的活动?通知、计划

2023-09-12 07:52:15 作者:年轻不拽世界怎么精彩

我使用GCM在我的应用程序,并使用NotificationManager创建一个通知,每当GCM消息received.Till现在一切都可以正常使用,并GCM消息被正确地显示在通知区域,但是当我点击的通知,它应该开始我的应用程序的活动,这将显示详细的消息是没有发生。每一次我点击通知没有启动任何活动,它仍然是is.My $ C $下创建的通知是:

I am using GCM in my application and also using NotificationManager to Create a Notification whenever GCM message is received.Till now everything is working perfectly and GCM message is showing correctly in Notification area, but when I click on the notification it should start an activity of my application which will display the message detail which is not happening. Every-time I click on notification it does not start any activity and it remains as is.My code for creating Notification is :

private void sendNotification(String msg) {
        SharedPreferences prefs = getSharedPreferences(
                DataAccessServer.PREFS_NAME, MODE_PRIVATE);
        mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(this, WarningDetails.class);
        Bundle bundle = new Bundle();
        bundle.putString("warning", msg);
        bundle.putInt("warningId", NOTIFICATION_ID);
        intent.putExtras(bundle);
        // The stack builder object will contain an artificial back stack for
        // the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(WarningDetails.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(intent);

        PendingIntent contentIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.weather_alert_notification)
                .setContentTitle("Weather Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);
        String selectedSound = prefs.getString("selectedSound", "");
        if (!selectedSound.equals("")) {
            Uri alarmSound = Uri.parse(selectedSound);
            mBuilder.setSound(alarmSound);

        } else {
            Uri alarmSound = RingtoneManager
                    .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(alarmSound);
        }

        if (prefs.getBoolean("isVibrateOn", false)) {
            long[] pattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500 };
            mBuilder.setVibrate(pattern);
        }

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }

我更新了我的code支持 preserving导航启动一个活动时,就像它在Gmail应用程序中使用Android开发者网站自那以后就停止发生working.Someone请指导我,我丢失或做错了本code什么。

I updated my code to support Preserving Navigation when Starting an Activity just like it happens in Gmail application using the Android developers website since then it stopped working.Someone Please guide me what I am missing or doing wrong in this code.

推荐答案

我的问题得到有效解决我只需要添加 PendingIntent.FLAG_ONE_SHOT 标记一样,所以我换成:

My problem got solved I just have to add PendingIntent.FLAG_ONE_SHOT flag as well , so I replaced :

PendingIntent contentIntent = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent contentIntent = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
                        | PendingIntent.FLAG_ONE_SHOT);
 
精彩推荐
图片推荐