The premise for Android Intent matching is to match the Intent values: Action, Category, Data/Type. If Component is filled with Componet, It is the Test in the previous example. class.
1. If you enter Action, if there is a program Manifest. if the IntentFilter segment of an Activity in xml defines the same Action, the Intent matches the target Action. If Type and Category are not defined in the Filter segment, the Activity matches. However, if there are more than two matching programs on the phone, a dialog box will pop up to indicate the matching.
- In-depth description of Android program conversion
- Details about Android plug-ins
- Complete parsing of Android applications
- Get started with Android applications
- In-depth analysis of four construction blocks of Android applications
The value of Action has many predefined meanings in Android. If you want to directly go to your own Intent receiver, you can add a custom Action value to the receiver's Android Intentr and set the Category value to "android. intent. category. DEFAULT "). Set this value to the Intent Action in your Android Intent to directly jump to your own Intent receiver. This Action is unique in the system.
2. data/type. You can use Uri as data, for example, Uri uri = Uri. parse (http://www.google.com); Intent I = new Intent (Intent. ACTION_VIEW, uri); During the Intent delivery process of the mobile phone, the data type is determined based on the scheme of the http://www.google.com. The phone's Brower can match it. In Brower's Manifest. xml, IntenFilter first contains ACTION_VIEW Action, which can also process http: type.
3. For classification Category, do not set it in Intent. If you write the Intent receiver, it is in Manifest. the IntentFilter of xml Activity contains android. category. DEFAULT. In this way, CategoryIntent is not set. the Intent of addCategory (String c);) will match this Category.
4, extras additional information), is a set of all other additional information. You can use extras to provide extended information for components. For example, if you want to perform the "send email" action, you can save the email title and body in extras, send to the email sending component.
Sample Code:
- public class HelloActivity extends Activity {
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // TODO Auto-generated method stub
- super.onCreateOptionsMenu(menu);
- menu.add(0, Menu.FIRST+1, 1, R.string.menu_open);
- menu.add(0, Menu.FIRST+2, 2, R.string.menu_edit);
- menu.add(0, Menu.FIRST+3, 3, R.string.menu_update);
- menu.add(0, Menu.FIRST+4, 4, R.string.menu_close);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- super.onOptionsItemSelected(item);
- switch(item.getItemId())
- {
- case Menu.FIRST + 1:
- {
- this.setTitle("Open Text!");
- Intent i = new Intent();
- i.setAction("test_action");
- if (Tools.isIntentAvailable(this,i))
- this.startActivity(i);
- else
- this.setTitle("the Intent is unavailable!!!");
- break;
- }
- case Menu.FIRST + 2:
- {
- this.setTitle("Edit Text!");
- break;
- }
- case Menu.FIRST + 3:
- {
- this.setTitle("Update Text!");
- break;
- }
- case Menu.FIRST + 4:
- {
- this.setTitle("Close Text!");
- break;
- }
- }
- return true;
- }