Sharing a track from the Spotify Android app with my app

时间:2015-10-29 11:07:52

标签: android android-intent spotify spotify-app

In recent versions of the Spotify Android app (3.9.0.965 at the time of writing) the Share -> Send to menu shows a bespoke list of options:

Select Recipient, Email, SMS and then a list of other apps (WhatsApp, Hangouts etc).

Is it possible for me to get my app onto that list? I'd like to be able to share a Spotify track with my app and play it.

2 个答案:

答案 0 :(得分:2)

  

我可以将我的应用程序放到该列表中吗?

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

例如,我们有一个包名为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 -> Send to该应用将不会显示。

现在将applicationId更改为build.gradle中列入白名单的软件包名称之一(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 -> Send to上下文菜单中可用,就像它是WhatsApp一样,您可以在此屏幕截图中看到:

enter image description here

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

答案 1 :(得分:0)

您需要在清单中提供活动(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>