简体   繁体   English

获取当前注册的 MediaBrowserServices 列表只在蓝牙 MediaBrowserService 中得到结果

[英]Obtaining a list of MediaBrowserServices currently registered results in only the bluetooth MediaBrowserService

I'm trying to build an app where one can start audio playback from WearOS.我正在尝试构建一个可以从 WearOS 开始音频播放的应用程序。 From what I can tell this requires an app on the phone to obtain a list of possible songs to be played.据我所知,这需要手机上的应用程序来获取可能播放的歌曲列表。 To do that I want to use the MediaBrowserService, like this example does.为此,我想使用 MediaBrowserService,就像这个例子一样。

However when I try to reproduce the listing of MediaBrowserServices, I only get the "Bluetooth audio" MediaBrowserService.但是,当我尝试重现 MediaBrowserServices 的列表时,我只得到“蓝牙音频”MediaBrowserService。 The example app on the other hand works fine and displays all apps.另一方面,示例应用程序运行良好并显示所有应用程序。

Here is the code I'm using:这是我正在使用的代码:

override fun onStart() {
    super.onStart()
    val mediaBrowserIntent = Intent(MediaBrowserServiceCompat.SERVICE_INTERFACE)

    val packageManager = this.packageManager
    val services = packageManager.queryIntentServices(mediaBrowserIntent, PackageManager.GET_RESOLVED_FILTER)
    val tv: TextView = findViewById(R.id.helloworld)
    val res = StringBuilder()
    for(info in services) {
        res.appendLine(info.serviceInfo.loadLabel(packageManager).toString())
    }
    tv.text = res.toString()
}

This is adapted from here .这是从这里改编的。

Do you know what might be causing the issue?您知道可能导致问题的原因是什么吗?

It looks like you need to properly handle the package visibility .看起来您需要正确处理package visibility
Try to add <queries> section to your manifest file with the correct intent filter signature:尝试使用正确的意图过滤器签名将<queries>部分添加到您的清单文件中:

<queries>
    <intent>
      <action android:name="android.media.browse.MediaBrowserService" />
    </intent>
</queries>

The sample app works because it targets SDK 29.示例应用程序之所以有效,是因为它以 SDK 29 为目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM