作者Ferich (纯粹的透明)
看板AndroidDev
标题[问题] Notification button 控制 app 播放
时间Fri Oct 25 14:24:10 2013
一开始去接值 第一次进入为null 按下notification後 会回传值来控制
Intent _Intent = getIntent();
String text = _Intent.getStringExtra("mode");
if(text=null)
{
pre();
next();
seek();
play();
}else if(text.equals("next"))
{
Toast.makeText(this, "next", Toast.LENGTH_LONG).show();
}
-----------------
当音乐播放时 show出 notification
CharSequence title = "Play_control";
int icon = R.drawable.player_icon;
long when = System.currentTimeMillis();
Notification noti = new Notification(icon, title, when + 10000);
noti.flags = Notification.FLAG_INSISTENT;
RemoteViews remoteView = new RemoteViews(this.getPackageName(),
R.layout.music_player_notification);
remoteView.setImageViewResource(R.id.cover, R.drawable.cover);
remoteView.setTextViewText(R.id.text, filename(music_list[position]));
Intent _Intent_next = new Intent(this, Player_music.class);
_Intent_next.putExtra("mode", "next");
remoteView.setOnClickPendingIntent(R.id.ibtn_player_control_next,
_PendingIntent_next);
noti.contentIntent = _PendingIntent_next;
----------
这样写 他的值的确可以回来 并且回到app show出toast
但是参考了sony的播放器与kkbox後
他们可以直接以notification操作 下一首 上一首 暂停 播放 不需要回到app.
但是小弟的写法会回去 并且开一个新的activity...
请问要如何控制原本的activity内的播放器 不需另开 也不需要把画面跳回app?
请有经验的捧油 参考一下 小弟疏漏的地方.
感谢看完~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.141.150.92
1F:→ ted66:广播试试 10/25 14:37
2F:→ Ferich:感谢您 搞定了 broadcast 正解 10/25 22:22