我正在尝试从应用程序内打开 Audible 并在启动时开始播放 Audible。 Audible 启动正常,但无法开始播放。
有声清单文件包含:
<receiver
android:name="com.audible.application.WidgetReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.audible.application.app.PAUSE" />
<action android:name="com.audible.application.app.PLAY" />
...
</intent-filter>
</receiver>
我创建了一个意图并将操作设置为清单文件中指定的操作。但是,Audible 启动但未开始播放。
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.audible.application");
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Set Intent Action as defined in Audible Manifest
intent.setAction("com.audible.application.app.PLAY");
getApplicationContext().startActivity(intent);
} else {
Toast.makeText(getApplication(), "Cannot launch Audible!", Toast.LENGTH_LONG).show();
}
}
});
}
我还可以尝试什么让 Audible 在发布时开始播放?
更新:
我已经成功使用 OK Google 启动并播放 Audible。首先我需要打开应用程序然后开始播放。
- OK Google 打开 Audible
- 好的谷歌播放
因此我想做的事情是可能的。但我不知道“OK Google play”在表面之下叫什么来让当前的玩家爆发出生命力。
//open audible
val intent =
packageManager.getLaunchIntentForPackage("com.audible.application")
intent?.let { startActivity(it) }
//simulate pressing the media play button after 1 second
Timer().schedule(object : TimerTask() {
override fun run() {
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).run {
dispatchMediaKeyEvent(
KeyEvent(
KeyEvent.ACTION_DOWN,
KEYCODE_MEDIA_PLAY_PAUSE
)
)
dispatchMediaKeyEvent(
KeyEvent(
KeyEvent.ACTION_UP,
KEYCODE_MEDIA_PLAY_PAUSE
)
)
}
}
}, 1000)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)