【发布时间】:2015-08-20 12:03:15
【问题描述】:
我的 Android 应用程序侦听 GCM 的推送通知。 在消息中,我放置了一个 json 对象,其中包含一些要在应用程序中处理的信息,因此我能够基于此启动不同的活动。 这里是启动 PendingIntent 的代码:
@Override
public void onMessageReceived(String from, Bundle data) {
...
...
// here i create the pending intent object based on json sent in the notification message from server side
...
...
// add the notification
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(defaultIcon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_my_icon))
.setContentTitle("My Application")
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(vibrate)
.setContentIntent(pendingIntent);
我不清楚为什么,如果应用程序没有运行,应用程序会在主 Activity 上启动。我想要的是它一直关闭,直到用户点击通知。那可能吗?有办法吗?
谢谢 大卫
【问题讨论】:
标签: android android-activity google-cloud-messaging android-pendingintent