【问题标题】:Sharing a track from the Spotify Android app with my app与我的应用共享来自 Spotify Android 应用的曲目
【发布时间】:2016-01-29 11:54:24
【问题描述】:

在最新版本的 Spotify Android 应用程序(撰写本文时为 3.9.0.965)中,Share -> Send to 菜单显示了一个定制的选项列表:

Select RecipientEmailSMS,然后是其他应用(WhatsApp、环聊等)的列表。

我是否可以将我的应用列入该列表?我希望能够与我的应用分享 Spotify 曲目并进行播放。

【问题讨论】:

    标签: android android-intent spotify spotify-app


    【解决方案1】:

    我是否可以将我的应用列入该列表?

    不,很遗憾,这是不可能的,即使您的清单配置正确,当您选择 Share -> Send to 时您也看不到您的应用,因为 Spotify 将仅显示一组预定义的应用(WhatsApp、Facebook Messenger、环聊)。

    例如,我们有一个应用程序包名称为com.example.spotify。将此intent-filter 添加到AndroidManifest.xml

    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>
    

    运行应用程序,但如果我们选择Share -&gt; Send to,应用程序将不会出现。

    现在在我们的 build.gradle 中将 applicationId 更改为列入白名单的包名称之一(com.whatsappcom.facebook.orcacom.google.android.talk):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        defaultConfig {
            applicationId "com.whatsapp"
            minSdkVersion 15
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    

    现在该应用程序可以在 Share -&gt; Send to 上下文菜单中使用,就像 WhatsApp 一样,您可以在此屏幕截图中看到:

    选择 WhatsApp,我们的应用将正确打开并接收来自 Spotify 的意图。

    【讨论】:

    • 我怀疑可能是这种情况。谢谢。
    【解决方案2】:

    您需要在清单中提供 Activity(SomeShareActivity) 并为其提供 IntentFilters

    <activity android:name=".SomeShareActivity">
      <intent-filter>
          <action android:name="android.intent.action.SEND" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="audio/*" />
          <data android:mimeType="video/*" /> 
      </intent-filter>  
    </activity>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-03
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      相关资源
      最近更新 更多