android - Google Play 音乐不再支持 media_play_from_search

标签 android android-intent android-music-player

Google Play 音乐不再出现在 INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH Intent 的“完成操作使用”列表中。我知道这曾经适用于 2.3,Pandora 和 Spotify 仍然出现。有没有人遇到过这个问题?

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH); 
intent.putExtra(SearchManager.QUERY, artistName); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent);

查看音乐 apk,我仍然可以通过 intent-filter 中的正确操作仍然可以看到该 Activity 仍然存在,但看起来他们缺少了原始发布在 blog post announcing this feature 中的类别默认值。

<activity android:name="com.google.android.music.VoiceActionsActivity" android:exported="true" android:process=":ui" android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
    </intent-filter>
</activity>

最佳答案

我找到了一个解决方法:可以手动将 Intent 的 ClassName 设置为 VoiceActionsActivity,如下所示:

Intent intent = new Intent();
intent.setClassName("com.google.android.music","com.google.android.music.VoiceActionsActivity");
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(SearchManager.QUERY, "chromeo - fancy footwork");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

Google Music 显然仍然不会出现在选择器对话框中,但是您可以添加一个自定义按钮来打开 Google Music。

编辑:这实际上是可行的,请参阅以下问题:add or remove options from createChooser但是,这将从应用程序中删除“设置默认值”按钮,因此它不是很完美。另一种选择是使用 getPackageManager().queryIntentActivities() 构建您自己的选择器。

关于android - Google Play 音乐不再支持 media_play_from_search,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084499/

相关文章:

android - 将样式应用于 Android ListView

android - 服务器上的网络服务调用不起作用

Android Activity 错误地重新父级到应用程序任务

android - 使用 Intent 启动媒体播放器

android - 无法使用 ExoPlayer 获取 AAC 文件的 getDuration()

android - 在 Android 上使用 FirebaseUI 的 GitHub oAuth

java - CipherOutputStream 和 FileOutputStream(someFile, true) 在追加数据时产生垃圾

android - resultActivity 上的 IMAGE_CAPTURE 文件尚不存在

android tabwidget Intent 选项卡刷新每次点击

Android 2.3 音乐播放器源代码