だから、たくさんの頭を悩ませた後、私は機知に富んでいます。通知にメディア プレーヤー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はnullです。それが違いを生むなら。
通知から音楽を一時停止して再生するにはどうすればよいですか?