我在GcmListenerService上有这段代码
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d("MESSAGE RECEIVED", data.toString());
try {
Bundle notification = (Bundle) data.get("notification");
if (notification != null) {
String title = notification.getString("title");
String text = notification.getString("body");
String target = notification.getString("target");
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse(target));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setContentIntent(contentIntent)
.setAutoCancel(true);
notificationManager.notify(1, mBuilder.build());
super.onMessageReceived(from, data);
}
} catch (Exception e ){
e.printStackTrace();
}
}
当应用程序打开时,意图效果很好,但如果您单击通知当应用程序关闭时,通知只会打开我的应用程序(而不是我预期的浏览器)。
有什么想法吗?