1

I'd like my app to be able to receive pictures/audiofiles etc. from the android-explorer. Apps like what's app, hangouts, gmail are already registered. How can I add my app as receiver?

I'm not sure what I should be looking for. Thank's for any hints:)

marcel
  • 3,231
  • 8
  • 43
  • 76

2 Answers2

3

Your <activity> will need an appropriate <intent-filter>, ideally filtering on MIME type.

For example, this set of <intent-filter> elements from the AOSP Music app allow it to respond to ACTION_VIEW on various audio file types, for files, HTTP streams, and ContentProvider streams:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file"/>
            <data android:mimeType="audio/*"/>
            <data android:mimeType="application/ogg"/>
            <data android:mimeType="application/x-ogg"/>
            <data android:mimeType="application/itunes"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:mimeType="audio/*"/>
            <data android:mimeType="application/ogg"/>
            <data android:mimeType="application/x-ogg"/>
            <data android:mimeType="application/itunes"/>
        </intent-filter>
        <intent-filter
            android:priority="-1">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="content" />
            <data android:mimeType="audio/*"/>
            <data android:mimeType="application/ogg"/>
            <data android:mimeType="application/x-ogg"/>
            <data android:mimeType="application/itunes"/>
        </intent-filter>
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

While the answer from CommonsWare is fine, I would like to add some information that might be helpful for others. In fact it took me years to finally find it out...

When selecting an audio file in a file manager, my application shall be listed for "open with".

While this does not work (like in the answer above):

            <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="file"/>
            <data android:mimeType="audio/*"/>
            <data android:mimeType="application/ogg"/>
            <data android:mimeType="application/x-ogg"/>
            <data android:mimeType="application/itunes"/>
        </intent-filter>

, this one works:

            <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="audio/*" />
        </intent-filter>

. Why? The "android:scheme" seems to be the culprit for whatever reason. But removing that line causes a severe error message in the IDE, which must be suppressed with the "ignore AppLinkUrlError" clause.

However, I did not test the other "schemes" mentioned above, so maybe there is another solution, but mine at least looks rather compact.

Now the question remains why my application's icon is so ugly compared to the others when the "open with" dialogue appears...