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

Mar*_*lar 8 java android intentfilter android-manifest kotlin

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>
Run Code Online (Sandbox Code Playgroud)

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?

小智 5

您需要为要使其应用程序成为默认应用程序的文件类型,操作或类别注册一个意图过滤器。然后,用户可以根据需要将您的应用选择为默认应用。

在此处查找有关意图和意图过滤器的更多信息。

只有通过root用户访问权限,才能将您的应用强制为默认应用。


Gen*_*mes 5

所以我的问题是,我必须向 android 清单文件中的意图过滤器添加哪些 mime 类型?

mimetype它只是描述内容的标准,它是下一步处理。这在 Android 中并不是什么新鲜事,您可以查看有关 Media Types Wiki 页面的更多信息。Android 文档中有关mimetype属性的此信息:

android:mimeType - MIME 媒体类型,例如 image/jpeg 或 audio/mpeg4-generic。子类型可以是星号通配符,表示任何子类型匹配

但是,正如您所看到的vnd,MIME 类型的前缀是“供应商前缀”,这意味着它不是官方的 IETF MIME 类型。因此,您需要为每个应用程序检查此类型。只是一些例子,我们在下面有什么。

笔记!为了设置默认应用程序,您需要先指定android.intent.action。因为它是进程交互之间的主要标志,所以 Launcher(例如)不会有mimetype,只有意图操作 android.intent.action.MAINandroid.intent.action.SET_WALLPAPER


相机:

<data android:mimeType="vnd.android.cursor.dir/image" />
<data android:mimeType="vnd.android.cursor.dir/video" />
Run Code Online (Sandbox Code Playgroud)

图像/视频/音频:

<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" />
....
Run Code Online (Sandbox Code Playgroud)

联系人:

<data android:mimeType="vnd.android.cursor.item/phone" />
<data android:mimeType="vnd.android.cursor.item/person" />
<data android:mimeType="vnd.android.cursor.dir/calls" />
Run Code Online (Sandbox Code Playgroud)

浏览器:

<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"/>
Run Code Online (Sandbox Code Playgroud)