Search code examples
androidandroid-intentspotifyspotify-app

Sharing a track from the Spotify Android app with my 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.


Solution

  • Is it possible for me to get my app onto that list?

    No, unfortunately this is not possible, even if your manifest is properly configured you cannot see your app when you choose Share -> Send to because Spotify will display only a predefined set of apps (WhatsApp, Facebook Messenger, Hangouts).

    For example we have an app with the package name com.example.spotify. Add this intent-filter to the 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>
    

    Run the app, but if we choose Share -> Send to the app will not appear.

    Now change the applicationId to one of the whitelisted package name (com.whatsapp, com.facebook.orca, com.google.android.talk) in our build.gradle:

    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'
            }
        }
    }
    

    Now the application is available in the Share -> Send to context menu as if it were WhatsApp, as you can see in this screenshot:

    enter image description here

    Choosing WhatsApp our app will correctly opens and receive the intent from Spotify.