【发布时间】:2014-10-17 23:13:52
【问题描述】:
所以,在头疼了很多之后,我无计可施。我的通知中有一个媒体播放器RemoteViews,我希望能够访问播放、暂停、上一个和下一个按钮。
我知道setOnClickPendingIntent() 将用于通过通知进行通信。但是,我想知道这将如何工作。
是否可以让服务处理点击?
我试过这个,但是没有用。我试图让我服务处理播放器的暂停和恢复:
rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);
Intent intent = new Intent(getApplicationContext(), MusicService.class);
intent.putExtra(REQUEST_CODE, PAUSE);
PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
rm.setPendingIntentTemplate(R.id.pause, pending);
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(rm)
.build();
NotificationManager mgr = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFICATION_ID, notif);
而我的IBinder 为空。如果这有所作为。
如何暂停和播放通知中的音乐?
【问题讨论】:
-
请停止删除过去的问题——这至少是你在这个主题上的第三个问题。
RemoteViews中的按钮在Notification中不起作用,最后我检查了。您应该使用与扩展通知关联的action buttons。setPendingIntentTemplate()与您的方案无关,因为您没有集合。
标签: android android-service android-pendingintent android-remoteview