【问题标题】:Google Play Music no longer supports media_play_from_searchGoogle Play 音乐不再支持 media_play_from_search
【发布时间】:2014-01-13 05:34:24
【问题描述】:

Google Play 音乐不再出现在 INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH 意图的“完成操作使用”列表中。我知道这曾经在 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,我仍然可以通过意图过滤器中的正确操作发现活动仍然存在,但看起来他们缺少最初发布在 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>

【问题讨论】:

  • 查看 VoiceActionsActivity 的源代码,我得出结论,他们确实只忘记了这一行。媒体搜索似乎已实现。有谁知道启动 Google Play 音乐的另一种方法? Shazam 可以通过使用数据“play.google.com/store/music/…”启动 action.VIEW Intent 来做到这一点。所以他们以某种方式检索了内部的歌曲 ID。也许通过非官方的 GMusic-API 之一?

标签: android android-intent android-music-player


【解决方案1】:

我找到了一种解决方法:可以手动将 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 音乐显然仍不会出现在选择器对话框中,但您可以添加一个自定义按钮来打开 Google 音乐。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    相关资源
    最近更新 更多