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/