Action of Intent

Intent means "intent, purpose" in Chinese, and can be understood as a "medium" or "messenger" for communication between different components.

The target component generally declares its own conditions through Intent, and generally filters through the elements in the component.

Intent consists of the following parts: action (action), data (data), category (Category), type (Type), component (Component), and extended information (Extra).

There are two ways for Intent to find the target component: first, specify it directly through the component name; second, filter and specify through the Intent Filter

Intent method to start different components
Component name Method name
Activity startActivity() startActivityForResult()
Service startService() bindService()
Broadcasts sendBroadcast() sendOrderedBroadcast() sendStickyBroadcast()

Common Activity Action Intent Constants
Constant Name Constant Value Meaning
ACTION_MAIN android.intent.action.MAIN Application entry
ACTION_VIEW android.intent.action.VIEW Display data to the user
ACTION_ATTACH_DATA android.intent.action.ATTACH_DATA indicate additional information to some other places Data
ACTION_EDIT android.intent.action.EDIT Show editable data
ACTION_PICK android.intent.action.PICK Select data
ACTION_CHOOSER android.intent.action.CHOOSER Show an Activity selector
ACTION_GET_CONTENT android.intent.action.GET_CONTENT Get content
ACTION_DIAL android. intent.action.GET_CONTENT show call panel
ACITON_CALL android.intent.action.DIAL call directly
ACTION_SEND android.intent.action.SEND text directly
ACTION_SENDTO android.intent.action.SENDTO select text
ACTION_ANSWER android.intent.action.ANSWER answer the phone
ACTION_INSERT android.intent.action.INSERT Insert data
ACTION_DELETE android.intent.action.DELETE Delete data
ACTION_RUN android.intent.action.RUN Run data
ACTION_SYNC android.intent.action.SYNC Synchronize data
ACTION_PICK_ACTIVITY android.intent.action.PICK_ACTIVITY Select Activity
ACTION_SEARCH android.intent.action.SEARCH search
ACTION_WEB_SEARCH android.intent.action.WEB_SEARCH web search
ACTION_FACTORY_TEST android.intent.action.FACTORY_TEST factory test entry point

Common BroadcastIntent Action Constants BroadcastIntent
Action String Constant Description
ACTION_TIME_TICK System time broadcast every minute
ACTION_TIME_CHANGED System time changed by setting
ACTION_TIMEZONE_CHANGED Time zone changed
ACTION_BOOT_COMPLETED System startup completed
ACTION_PACKAGE_ADDED New application apk package installed
ACTION_PACKAGE_CHANGED Existing application apk package changed
ACTION_PACKAGE_REMOVED existing app apk package removed
ACTION_UID_REMOVED user id removed

The Action and Data properties of the Intent match the
Action property Data property description
ACTION_VIEW content://contacts/people/1 Display the contact information with id 1
ACTION_DIAL content://contacts/people/1 Display the phone number of the contact with id 1 In the dialing interface
ACITON_VIEW tel:123 Display the contact information with the phone number 123
ACTION_VIEW http://www.google.com Browse the website in the browser
ACTION_VIEW file://sdcard/mymusic.mp3 Play MP3
ACTION_VIEW geo:39.2456, 116.3523 show map

Common Category Constants
Category String Constant Description
CATEGORY_BROWSABLE The target activity can be activated by clicking a link in a web browser (for example, clicking a picture link in the browser)
CATEGORY_GADGET Indicates that the target activity can be embedded into other activities
CATEGORY_HOME The target activity is HOME Activity, that is, the
Activity displayed after the phone is turned on, or the Activity displayed after pressing the HOME
key

Common Extra Constants
Extra Key Value String Constant Description
EXTRA_BCC String array
with BCC address EXTRA_CC String array with email CC address
EXTRA_EMAIL String array with email address
EXTRA_INTENT Intent when using ACTION_PICK_ACTIVITY action The key of the option
EXTRA_KEY_EVENT The KeyEvent object of the case that triggers the Intent EXTRA_PHONE_NUMBER
The key of the phone number string when using the action related to making a call, the type is String
EXTRA_SHORTCUT_ICON The description information of the shortcut when creating a shortcut in HomeActivity using ACTION_CREATE_SHORTCUT.
Among them, ICON and ICON_RESOURCE describe the icon of the shortcut, and the types are Bitmap and ShortcutIconResource respectively. INTENT describes the Intent object corresponding to the shortcut. NAME describes the name of the shortcut.
EXTRA_SHORTCUT_ICON_RESOURCE EXTRA_SHORTCUT_INTENT EXTRA_SHORTCUT_NAME EXTRA_SUBJECT The key to describe the subject of the message
EXTRA_TEXT When using the ACTION_SEND action, it is used to describe the text message to be sent, the type is CharSequence
EXTRA_TITLE When the ACTION_CHOOSER action is used, the key that describes the dialog title, the type is CharSequence
EXTRA_UID When using the ACTION_UID_REMOVED action, the key describing the deleted user id, the type is int

Class in the Android.telephony package
Class Name Description
CellLocation An abstract class that represents the location of the device
PhoneNumberFormattingTextWather Monitors a TextView control, and if there is a phone number input, it uses the formatNumber() method to process the phone number
PhoneNumberUtils Contains various tools for processing phone number strings
PhoneStateListener A listener class that monitors changes in phone state in the phone.
ServiceState contains phone state and related service information.
TelephonyManager provides access to phone service information in the phone.

The classes related to the SMS service are mainly in the package android.telephony.gsm
Class name description
GsmCellLocation Indicates the base station location of the GSM mobile phone
SmsManager Manages various SMS operations
SmsMessage Indicates specific SMS messages

1. Usage of Intent:
(1) Jump with Action 1. Jump
with Action, if there is a program's AndroidManifest.xml in the IntentFilter section of an Activity that contains the same Action, then this Intent is the same as this Target Action matches. If Type and Category are not defined in this IntentFilter segment, then this Activity matches. But if there are more than two programs in the phone that match, a dialog box will pop up to prompt for instructions.
There are many predefined Action values ​​in Android. If you want to go directly to your own defined Intent receiver, you can add a custom Action value to the receiver's IntentFilter (and set the Category value to "android" .intent.category.DEFAULT"), in your Intent set the value of Intent Action, you can jump directly to your own Intent receiver. Because this Action is unique in the system.
2, data/type, you can use Uri as data, such as Uri uri = Uri.parse( http://www.google.com );
Intent i = new Intent(Intent.ACTION_VIEW,uri); Intent of mobile phone During the distribution process, the data type will be determined according to the scheme of http://www.google.com . The Brower of the mobile phone can match it. In the IntenFilter of Brower's Manifest.xml, there is ACTION_VIEW Action first, and it can also handle the type of http:.
3. As for the category Category, generally do not set it in the Intent. If you write the receiver of the Intent, include android.category.DEFAULT in the IntentFilter of the Activity of Manifest.xml, so that all categories are not set (Intent.addCategory(Intent.addCategory( String c);) Intent will match this Category.
4, extras (additional information), is a collection of all other additional information. Using extras can provide extended information for the component. For example, if you want to perform the action of "send email", you can save the title and body of the email in extras and pass it to the email sending component.
(2) Using the class name to jump
to the Intent is responsible for describing the action, action-related data, and additional data of an operation in the application. Android is responsible for finding the corresponding component according to the description of the Intent, passing the Intent to the calling component, and Complete the invocation of the component. Intent here plays the role of decoupling between the caller and the callee. Intent delivery process, to find the target consumer (another Activity, IntentReceiver or Service), that is, the responder of the Intent.
Intent intent = new Intent();
intent.setClass(context, targetActivy.class);
//Or use Intent intent = new Intent(context, targetActivity.class);

startActivity(intent);
But pay attention to jumping with class name, you need to declare activity in AndroidManifest.xml

2. Usage of several Intent Intent
is often used in android. Whether it's page pulling, transferring data, or calling external programs, system functions must use intents. After doing some examples of intents, I sorted out the intents, hoping to be useful to everyone. Because the content of the intent is too much, it is impossible to really write it all, and it is inevitable that there will be leftovers. I will update it at any time in the future. If you have questions or new intent content, hope to communicate.
★Intent Daquan:
1. Search content from google
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "searchString")
startActivity(intent);

2.浏览网页
Uri uri = Uri.parse(“http://www.google.com“);
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

3.显示地图
Uri uri = Uri.parse(“geo:38.899533,-77.036476”);
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);

4.路径规划
Uri uri = Uri.parse(“http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en“);
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);

5. Make a call
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);

6. Call the texting program
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);

7.发送短信
Uri uri = Uri.parse(“smsto:0800000123”);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra(“sms_body”, “The SMS text”);
startActivity(it);
String body=”this is sms demo”;
Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(“smsto”, number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);

8.发送彩信
Uri uri = Uri.parse(“content://media/external/images/media/23”);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(“sms_body”, “some text”);
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType(“image/png”);
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append(“file://”);
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(“mmsto”, number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity(intent);

9.发送Email
Uri uri = Uri.parse(“mailto:[email protected]”);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, “[email protected]”);
it.putExtra(Intent.EXTRA_TEXT, “The email body text”);
it.setType(“text/plain”);
startActivity(Intent.createChooser(it, “Choose Email Client”));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={“[email protected]”};
String[] ccs={“[email protected]”};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, “The email body text”);
it.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
it.setType(“message/rfc822”);
startActivity(Intent.createChooser(it, “Choose Email Client”));

Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
it.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/mysong.mp3”);
sendIntent.setType(“audio/mp3”);
startActivity(Intent.createChooser(it, “Choose Email Client”));

10.播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(“file:///sdcard/song.mp3”);
it.setDataAndType(uri, “audio/mp3”);
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, “1”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

11.uninstall apk
Uri uri = Uri.fromParts(“package”, strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);

12.install apk
Uri installUri = Uri.fromParts(“package”, “xxx”, null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

  1. 打开照相机
    <1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
    this.sendBroadcast(i);
    <2>long dateTaken = System.currentTimeMillis();
    String name = createName(dateTaken) + “.jpg”;
    fileName = folder + name;
    ContentValues values = new ContentValues();
    values.put(Images.Media.TITLE, fileName);
    values.put(“_data”, fileName);
    values.put(Images.Media.PICASA_ID, fileName);
    values.put(Images.Media.DISPLAY_NAME, fileName);
    values.put(Images.Media.DESCRIPTION, fileName);
    values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
    Uri photoUri = getContentResolver().insert(
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

    Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    startActivityForResult(inttPhoto, 10);

14.从gallery选取图片
Intent i = new Intent();
i.setType(“image/*”);
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);

  1. Open recorder
    Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
    startActivity(mi);

16.显示应用详细列表
Uri uri = Uri.parse(“market://details?id=app_id”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar

I just failed to find the app id, and found that the package name can also be used
Uri uri = Uri.parse(“market://details?id=”);
This is much simpler

17寻找应用
Uri uri = Uri.parse(“market://search?q=pname:pkg_name”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application

18 Open Contact List
<1>
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);

<2>   
Uri uri = Uri.parse("content://contacts/people");   
Intent it = new Intent(Intent.ACTION_PICK, uri);   
startActivityForResult(it, REQUEST_TEXT);   

19 打开另一程序
Intent i = new Intent();
ComponentName cn = new ComponentName(“com.yellowbook.android2”,
“com.yellowbook.android2.AndroidSearch”);
i.setComponent(cn);
i.setAction(“android.intent.action.MAIN”);
startActivityForResult(i, RESULT_OK);

20.调用系统编辑添加联系人(高版本SDK有效):
Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);
it.setType(“vnd.android.cursor.item/contact”);
//it.setType(Contacts.CONTENT_ITEM_TYPE);
it.putExtra(“name”,”myName”);
it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, “organization”);
it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,”email”);
it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,”homePhone”);
it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
“mobilePhone”);
it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
“workPhone”);
it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,”title”);
startActivity(it);

21.调用系统编辑添加联系人(全有效):
Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.NAME, “My Name”);
intent.putExtra(Contacts.Intents.Insert.PHONE, “+1234567890”);
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
intent.putExtra(Contacts.Intents.Insert.EMAIL, “[email protected]”);
intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);
startActivity(intent);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325493625&siteId=291194637