Intent, Action, Daquan

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 the Intent, which is generally filtered through the <intent-filter> element 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 the specification through the Intent Filter

Intent's method of launching 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 displays data to the user
ACTION_ATTACH_DATA android.intent.action.ATTACH_DATA indicates additional information to some data elsewhere
ACTION_EDIT android.intent.action.EDIT display editable data  
ACTION_PICK android.intent.action.PICK selection data  
ACTION_CHOOSER android.intent.action.CHOOSER displays an Activity selector  
ACTION_GET_CONTENT android.intent.action.GET_CONTENT get content  
ACTION_DIAL android.intent.action.GET_CONTENT display the call panel  
ACITON_CALL android.intent.action.DIAL call directly  
ACTION_SEND android.intent.action.SEND direct text message  
ACTION_SENDTO android.intent.action.SENDTO select texting  
ACTION_ANSWER android.intent.action.ANSWER answer the call  
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 sync data  
ACTION_PICK_ACTIVITY  android.intent.action.PICK_ACTIVITY  选择Activity  
ACTION_SEARCH android.intent.action.SEARCH search  
ACTION_WEB_SEARCH  android.intent.action.WEB_SEARCH  Web搜索  
ACTION_FACTORY_TEST android.intent.action.FACTORY_TEST Factory test entry point     


Common BroadcastIntent Action constant 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 change  
ACTION_BOOT_COMPLETED System boot completed  
ACTION_PACKAGE_ADDED The new application apk package is installed  
ACTION_PACKAGE_CHANGED Existing application apk package changes  
ACTION_PACKAGE_REMOVED Existing app apk package is removed  
ACTION_UID_REMOVED User id was removed     


Intent's Action and Data properties match  
Action property Data property description  
ACTION_VIEW content://contacts/people/1 displays the contact information with id 1  
ACTION_DIAL content://contacts/people/1 displays the phone number of the contact whose id is 1 in the dialing interface  
ACITON_VIEW tel:123 Displays the contact information with the phone number 123  
ACTION_VIEW http://www.google.com Browse the site in a browser  
ACTION_VIEW  file://sdcard/mymusic.mp3  播放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 (eg, clicking an image link in the browser)  
CATEGORY_GADGET indicates that the target Activity can be embedded into other Activity  
CATEGORY_HOME The target Activity is the HOME Activity, that is, the Activity displayed after the phone is powered on, or the Activity displayed after pressing the HOME button  
CATEGORY_LAUNCHER indicates that the target Activity is the Activity that is executed with the highest priority in the application  
CATEGORY_PREFERENCE indicates that the target Activity is a preference set Activity


Common Extra Constants
Extra key value string constant description
EXTRA_BCC String array with BCC addresses  
EXTRA_CC String array with email CC addresses  
EXTRA_EMAIL String array containing email addresses  
EXTRA_INTENT A key with the Intent option when using the ACTION_PICK_ACTIVITY action  
EXTRA_KEY_EVENT triggers the KeyEvent object of the case of this Intent  
EXTRA_PHONE_NUMBER The key of the phone number string when using the Action related to making a phone call, the type is String  
EXTRA_SHORTCUT_ICON Use ACTION_CREATE_SHORTCUT to create a shortcut in HomeActivity, the description of the 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 key describing the subject of the message  
EXTRA_TEXT When using the ACTION_SEND action, it is used to describe the text information to be sent, the type is CharSequence  
EXTRA_TITLE When using the ACTION_CHOOSER action, the key describing the title of the dialog box, the type is CharSequence  
EXTRA_UID When using the ACTION_UID_REMOVED action, the key describing the deleted user id, the type is int    


Classes in the Android.telephony package  
class name description  
CellLocation abstract class representing device location  
PhoneNumberFormattingTextWather monitors a TextView control and uses the formatNumber() method to process the phone number if there is a phone number input  
PhoneNumberUtils contains various utilities for working with phone number strings  
PhoneStateListener is a listener class for monitoring phone state changes in the phone  
ServiceState contains phone state and related service information  
TelephonyManager provides access to telephony 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 represents a specific text message  


1.Intent usage:
(1) Jump with Action
1. Use Action to jump. If there is a program's AndroidManifest.xml in the IntentFilter section of an Activity that defines the same Action, then the Intent matches the target Action. 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); During the Intent distribution process of the mobile phone, the data type 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) Jump with class name
    Intent is responsible for describing the action of an operation in the application, the data involved in the action, and the additional data. According to the description of the Intent, Android is responsible for finding the corresponding component, passing the Intent to the calling component, and completing 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 directly 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  
<activity android:name="targetActivity"></activity>
2. The 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. Browse the web
Uri uri = Uri.parse("http://www.google.com");
Intent it  = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

3. Display the map
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);

4. Path planning
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 program for texting
Intent it = new Intent(Intent.ACTION_VIEW);    
it.putExtra("sms_body", "The SMS text");    
it.setType("vnd.android-dir/mms-sms");    
startActivity(it);

7. Send SMS
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. Send MMS
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. Send 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. Play multimedia   
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);

13. Turn on the camera
<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. Select image from gallery
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult (i, 11);

15. Turn on the recorder
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity (mi);

16. Show application detail list       
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=<packagename>");
This is much simpler

17 Find Apps       
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 Open another program
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. Call the system editor to add contacts (higher version SDK is valid):
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. Call the system editor to add contacts (all valid):
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://10.200.1.11:23101/article/api/json?id=326796982&siteId=291194637