如何获取有关Oreo当前正在播放的曲目的信息?

时间:2018-12-21 17:00:51

标签: java android

我正在使用BroadcastReceiver

但是没有用。当我开始播放音乐播放器并打开一个应用程序时,Toast没有显示。

在调试中,所有变量均为null;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = findViewById(R.id.status);
    IntentFilter iF = new IntentFilter();
    iF.addAction("com.android.music.metachanged");
    iF.addAction("com.android.music.playstatechanged");
    iF.addAction("com.android.music.playbackcomplete");
    iF.addAction("com.android.music.queuechanged");
    iF.addAction("com.miui.player.metachanged");
    iF.addAction("com.miui.player.playstatechanged");
    iF.addAction("com.miui.player.playbackcomplete");
    iF.addAction("com.miui.player.

    registerReceiver(mReceiver, iF);

}

public BroadcastReceiver mReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        String cmd = intent.getStringExtra("command");
        Log.v("tagtag ", action + " / " + cmd);
        String artist = intent.getStringExtra("artist");
        String album = intent.getStringExtra("album");
        String track = intent.getStringExtra("track");
        Log.v("tagtag", artist + ":" + album + ":" + track);
        Toast.makeText(MainActivity.this, track, Toast.LENGTH_SHORT).show();
    }
};

0 个答案:

没有答案