【发布时间】:2014-04-08 09:43:01
【问题描述】:
我正在为我的音乐播放器构建一个notification,以便显示正在播放的音乐。
但我想添加一个功能,当我触摸它时。它打开了我的布局player.xml。通过MainActivity.class部署。
我在 developer.android.com 上研究了通知,并找到了一种在单击通知时进行部署和活动的方法。但它没有用。
这是我当前的代码 -
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentTitle(songsList.get(songIndex).get("songTitle"));
builder.setContentText("NexPlay™");
builder.setTicker(songsList.get(songIndex).get("songTitle"));
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setSmallIcon(R.drawable.play_default);
builder.setAutoCancel(true);
builder.setPriority(0);
builder.setOngoing(true);
Notification notification = builder.build();
NotificationManager notificationManger =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManger.notify(01, notification);
感谢大家的回答!
我加了
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, NotificationToPlayer.class), 0);
builder.setContentIntent(pendingIntent);
到我的通知,效果很好!
【问题讨论】:
-
您必须在代码中哪里设置
Notification Content Intent?
标签: java android class layout notifications