我收到来自GCM的通知,收到通知时,我想显示Google Play来安装应用。
我试图这样
NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse("market://details?id=com.karya.kot")); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify( 0, notification);
但是,当我单击通知时,它不会进入Google Play吗?我做错了什么?
我已经在手机中测试了此代码,并且可以正常工作
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int sb2value = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING); NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "Testomg", System.currentTimeMillis() + 5000); Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse("market://details?id=com.karya.kot")); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); notification.setLatestEventInfo(getApplicationContext(), "Google Play", "Download app", intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification);