【发布时间】:2014-04-15 05:54:41
【问题描述】:
您好如何处理推送通知点击我需要打开带有特定片段的活动, 我有两种状态,例如应用程序已关闭和应用程序已打开,当应用程序关闭时,我需要使用 MyFragment.class 打开家庭活动,如果应用程序已打开,则我需要显示对话框,如果是,我需要查看详细信息我需要打开像MyFragment这样的特定片段,如果没有我需要dissmis对话框,,,如何实现它......
@SuppressWarnings("deprecation")
@Override
public void update(java.util.Observable observable, Object data) {
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
long when = System.currentTimeMillis();
Notification notification = new Notification(R.drawable.ic_launcher,
data.toString(), when);
String title = this.getString(R.string.app_name);
Intent notificationIntent = new Intent(this, MainActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(this, title, data.toString(), intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
Log.d("GCM_TOKEN", data.toString());
Toast.makeText(this, "Error: " + data.toString(), Toast.LENGTH_LONG)
.show();
}
谢谢
【问题讨论】:
标签: android push-notification android-notifications android-notification-bar