通知打开谷歌播放

时间:2013-12-27 00:31:53

标签: java android

我想点击打开Goog​​le Play时发出通知。

我正在使用谷歌Api示例。

另一个问题是,通知ID可以是静态的吗?

neceesary是否在androidmanifest中添加了其他东西?

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build()); 

1 个答案:

答案 0 :(得分:2)

通知 ID仅用于通知标识,如果之前的通知仍然可见,系统会从通知对象的内容进行更新。如果先前的通知已被取消,则会创建新通知。

您必须将您的意图ResultActivity添加到manifest.xml文件中,如果您设置了Notification声音,那么您必须将Vibrate权限添加到您的manifest.xml文件中。