我看到许多应用程序在内置均衡器中打开系统(谷歌播放音乐、Spotify、三星音乐播放器)。直接使用,无需自己从头编写。这些应用程序如何做到这一点?我找不到解决方案。
} else if (id == R.id.action_fx) {
Intent intent = new Intent();
intent.setAction("android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL");
if ((intent.resolveActivity(getPackageManager()) != null)) {
startActivity(intent);
} else {
Intent intent11 = new Intent(MainActivity.this, Help.class);
intent11.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent11);
// No equalizer found :(
}
return true;
最佳答案
以下应该可以启动默认均衡器 Activity
:
Intent intent = new Intent(AudioEffect
.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
if ((intent.resolveActivity(getPackageManager()) != null)) {
startActivityForResult(intent, REQUEST_EQ);
} else {
// No equalizer found :(
}
Spotify 基本上是一样的,其他的没查过。
startActivityForResult()
的必要性在 docs 中有解释。 :
The intent carries a number of extras used by the player application to communicate necessary pieces of information to the control panel application.
The calling application must use the
android.app.Activity#startActivityForResult(Intent, int)
method to launch the control panel so that its package name is indicated and used by the control panel application to keep track of changes for this particular application.
关于android - 如何在 Android 中以编程方式打开内置均衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37774660/