【问题标题】:Android intent to enter a search query for google play music appAndroid意图输入谷歌播放音乐应用的搜索查询
【发布时间】:2017-08-31 18:06:58
【问题描述】:

您好,我正在尝试使用我的应用提供的字符串自动填充 Google Play 音乐上的搜索栏。我目前打算打开 Google Play 音乐,但我无法找到合适的参数来填充 Google Play 音乐上的搜索栏。 这是我的代码

Intent intent = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage("com.google.android.music");
startActivity(intent);

有人知道正确的意图吗?提前致谢

【问题讨论】:

  • 你确定有这种可能吗?很少有活动真正接受这样的参数。
  • 值得一试,我可以在 Google Play Store 应用程序中填满搜索栏。 @GabeSechan

标签: android android-intent


【解决方案1】:

我找到了我的问题的答案。 The documentation can be found here. 我不得不选择 google play music 作为我的默认音乐播放器,但在完成之后,歌曲会使用以下代码自动搜索/播放。

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
            intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, track.getArtistName());
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track.getName());
            intent.putExtra(SearchManager.QUERY, track.getName());

            startActivity(intent);

【讨论】:

  • @SabariKarthik 这是我正在使用的一个对象,其中包含一个我想作为意图的一部分传入的字符串
【解决方案2】:

以下是播放具有给定标题的歌曲的工作代码。

String title = "Iridescent";

Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
            intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
                    MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE,title);               
            intent.putExtra(SearchManager.QUERY,title);
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多