Android-implicit Intent, android-intent
Implicit Intent indicates the activity to be opened, which can be opened by implicit intent.
The main components of an implicit intent:
1. action.
It is usually expressed as a constant of the intent class. For example:
Access to view a URL Intent. ACTION_VIEW
Send Intent. ACTION_SEND
2.DataLocation.
Data outside the device, such as a webpage URL
URI pointing to a file
Point to a content URI of a record in ContentProvider
3. the type operation involvesData Type
Such as text/html or audio/mpeg3.
If an intent contains a certain type of data, the data type can be inferred from it.
4. Optional category categories
A category is used to describe how to use an activity.
Android. intent. category. LAUNCHER: the activity should be displayed in the top-level app LAUNCHER.
Android. intent. category. INFO: although the activity shows the package information to the user, it should not be displayed in the starter.
Android. intent. category. DEFAULT: the DEFAULT category must be explicitly set in the intent filter. If action tells the operating system what the activity can do;
The DEFAULT category tells the operating system what activity is willing to do. The DEFAULT category is actually implicitly added to almost every implicit intent. (The only exception is the LAUNCHER category)
For example, an explicit intent can also contain extra information. However, the operating system does not use any extra attached to the implicit intent when looking for a suitable activity.
Note that the implicit intent action and data can also be used together with the explicit intent. This is equivalent to requiring a specific activity to process a specific task.
For example, if you want a simple implicit intent used to view a website, you must
Action: Intent. ACTION_VIEW
URL: uri data of a specific URL
<intent-filter> <action android:name="android.intent.action.VIEW"/> <data android:scheme="http" android:host="www.baidu.com"/> <category android:name="android.intent.category.DEFAULT"/></intent-filter>
Additionally, because the implicit intent does not explicitly tell the activity to be opened, there may be no suitable application on the device. At this time, the application will crash. Therefore, before using the implicit intent, we should first perform a security check to determine whether there is a suitable activity.
Intent i=new Intent();....PackageManager pm=getActivity().getPackageManager();List<ResolveInfo> activities=pm.queryIntentActivities(i,0);if(activities.size()>0){//safe}else{//no suitable activity for this intent}