Уведомление о намерениях без дополнительных услуг - PullRequest
2 голосов
/ 30 ноября 2011

Я пытаюсь запустить намерение из уведомления, но по какой-то причине я не знаю, что дополнительное не всегда отправляется с намерением. Здесь я создаю намерение:

NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
                    mContext.getString(R.string.text), 0);

Intent intents = new Intent(mContext, DataAppTabs.class);
intents.putExtra(DataAppTabs.REQUEST, DataAppTabs.REQUEST_DMTAB);
intents.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent launchIntent =    PendingIntent.getActivity(mContext.getApplicationContext(), DataAppTabs.REQUEST_DMTAB, intents, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(mContext, "Info", mContext.getString(R.string.enginedmnotification_rebootneeded), launchIntent);
notification.flags = Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(DataAppTabs.REQUEST_DMTAB, notification);

В классе DataAppTabs я переопределил onCreate () и onNewIntent (). Когда появляется уведомление, если я щелкаю по нему, открывается правильное действие (DataAppTabs, которое является TabActivity), оно запускает onCreate или onNewIntent, если действие уже было запущено, но дополнительный запрос REQUEST не всегда устанавливается (getExtras () иногда ноль).

Я нашел здесь тот же вопрос с ответами, в которых говорилось, что мне пришлось использовать флаг «FLAG_ACTIVITY_SINGLE_TOP», но он все еще не работает постоянно, и я не могу воспроизвести проблему каждый раз.

Я что-то не так сделал? Спасибо

1 Ответ

0 голосов
/ 30 ноября 2011
    // Displaying Notification
              NotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
               Notification notification = new Notification(R.drawable.icon, "MyNotification", System.currentTimeMillis());
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Sample.class), 0);
                notification.setLatestEventInfo(getApplicationContext(), "Notification Title", "Notification Data", contentIntent);
                notification.flags = Notification.FLAG_INSISTENT;

                            int NOTIFICATION_ID=(int)System.currentTimeMillis();
                manager.notify(NOTIFICATION_ID, notification);

// Sample.class is the activity to which you want to go when you click on Notification
...