Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set apps as default or let the user select the app?

Currently I'm trying to create a bunch of simple Android apps to replace the default apps with them.

I already saw in this post how to set the SMS app as default:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="vnd.android-dir/mms-sms" />
</intent-filter>

But I was wondering how to achieve the same for these apps:

  • Camera application (To take pictures)
  • Gallery/Photo application (To select and view images)
  • Contact application (To view, edit, delete and call contacts)
  • Telephone application (To call contacts/telephone numbers and receive incoming calls)
  • Internet browser application (To browse the internet)
  • Keyboard application (To write text like in the default keyboard)
  • Launcher application (To display all installed apps on the home screen)

I already noticed that it's nearly impossible to set the app as default app programmatically without the user's interaction. This would be the main goal, but it would be also okay if the user can choose which application they want to use as the default application. But I want to be sure that the apps which I listed above are selectable. So my question is, what mime types do I have to add to the intent filters in the android manifest file?

like image 377
Marvin Klar Avatar asked Mar 19 '19 09:03

Marvin Klar


2 Answers

So my question is, what mime types I have to add to the intent filters in the android manifest file?

mimetype it's just standard of describing content, and it's next processing. This is not something new in Android, you can check more information about Media Types Wiki page. This information about mimetype attribute in the the Android Documentation:

android:mimeType - A MIME media type, such as image/jpeg or audio/mpeg4-generic. The subtype can be the asterisk wildcard to indicate that any subtype matches

However as you can see the vnd prefix on a MIME type is a "vendor prefix", meaning that it is not an official IETF MIME type. So you will need to check this type for each application. Just some examples, what we have below.

Note! In order to set default application, you need to specify android.intent.action first. Because it's main flags between process interaction, so Launcher (for ex.) won't have mimetype, and only intent actions android.intent.action.MAIN, android.intent.action.SET_WALLPAPER.


Camera:

<data android:mimeType="vnd.android.cursor.dir/image" />
<data android:mimeType="vnd.android.cursor.dir/video" />

Image/Video/Audio:

<data android:mimeType="video/*" />
<data android:mimeType="video/mpeg4" />
<data android:mimeType="video/mp4" />
<data android:mimeType="video/3gp" />
......
<data android:mimeType="image/*" />
<data android:mimeType="application/sdp" />
......
<data android:mimeType="audio/x-mpegurl" />
<data android:mimeType="audio/mpegurl" />
<data android:mimeType="application/vnd.apple.mpegurl" />
<data android:mimeType="application/x-mpegurl" />
....

Contacts:

<data android:mimeType="vnd.android.cursor.item/phone" />
<data android:mimeType="vnd.android.cursor.item/person" />
<data android:mimeType="vnd.android.cursor.dir/calls" />

Browser:

<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
<data android:mimeType="vnd.android.cursor.item/postal-address" />
<data android:mimeType="vnd.android.cursor.dir/bookmark"/>
<data android:mimeType="vnd.android.cursor.item/download"/>
like image 174
GensaGames Avatar answered Sep 23 '22 02:09

GensaGames


You need to register an Intent Filter for the file types, actions, or categories for which you want your app to be the default app. The user will then be able to choose your app as the default app if they want to.

Look here for more information on Intents and Intent Filters.

Forcing your app as the default app for something is only possible with root access.

like image 38
David3103 Avatar answered Sep 25 '22 02:09

David3103