1.Activity
Methods: Startactivityforresult and Onactivityresult echo each other,
The behavior that is used to process the returned results, such as when a user clicks on a picture to publish on a Weibo
2.Uri
static method:
Uri.fromparts ("Package", "Com.hq.myapp", null);
Uri.parse (mailto:[email protected])
Uri.fromfile (New File)
Common methods:
GetPath ();
3.Intent
Common methods:
Addcategory (intent.category_openable);
SetType ("image/*");
SetData (ContactsContract.Contacts.CONTENT_URI);
Addflags (int flags);
Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Button BT=(Button) Findviewbyid (R.ID.BT); Bt.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {//the role of intent://1. Invoking the browserUri uri1=uri.parse ("http://www.baidu.com");//DataIntent intent1=NewIntent (); Intent1.setaction (Intent.action_view); Intent1.setdata (URI1); //2. Phone Call functionUri uri2=uri.parse ("tel:10086"); Intent Intent2=NewIntent (ANDROID.CONTENT.INTENT.ACTION_CALL,URI2); //3. Send SMSUri uri3=uri.parse ("smsto:10086"); Intent Intent3=NewIntent (INTENT.ACTION_SENDTO,URI3); Intent3.putextra ("Sms_body", "Welcome to Android World"); //4. Send email, you may have more than one mail client, so useIntent.createchooser () Create a action_chooser intent//1. The recipient's address, the action to send the messageUri uri4=uri.parse ("Mailto:[email protected]"); Intent Intent4=NewIntent (INTENT.ACTION_SEND,URI4); //2. Own mail client, and send the contentIntent4.putextra (Intent.extra_email, "[EMAIL protected]"); Intent4.putextra (Intent.extra_text,"Android Mail"); //3. Specify the type of data, default valueIntent4.settype ("Text/plain"); //Createchooser Start IntentStartActivity (Intent.createchooser (intent4, "Select Email client")); //6. Play multimedia files//1. Action: Show ViewIntent intent6=NewIntent (); Intent6.setaction (Intent.action_view); //2. Set data and typeUri uri6=uri.parse ("File:///sdcard/01.mp3"); Intent6.setdataandtype (Uri6,"Audio/mp3"); //7. Install apk file//1. Action: Show ViewIntent intent7=NewIntent (); Intent7.setaction (Intent.action_view); //2.setDataAndType//2.1 Get the path to file: Environment.getexString filename=environment.getexternalstoragedirectory () + "mapp.apk"; Intent7.setdataandtype (Uri.fromfile (NewFile (filename), "application/vnd.android.package-archive"); //8. Uninstall the application: Unloaded path (URI), unloaded action (delete)Uri uri8=uri.fromparts ("package", "Com.hq.myapp",NULL); Intent intent8=NewIntent (INTENT.ACTION_DELETE,URI8); //9. Access the contact personIntent intent9 =NewIntent (); Intent9.setaction (Intent.action_view); Intent9.setdata (ContactsContract.Contacts.CONTENT_URI); }}); //10. Select a picture from the gallery//Startactivityforresult (Intent, Requestcode); //the intent is going to return a picture (result), so call the method//onactivityresult (int requestcode, int resultcode, Intent data)//The two code matches which intent returned, and intent contains the result data selected by the user. Intent intent=NewIntent (); //1. Action: Get content Get_contentintent.setaction (intent.action_get_content); //2. Data type type,image/*Intent.settype ("image/*"); //3.add Category: The content must be openintent.addcategory (intent.category_openable); //4. Start the Forresult method,Startactivityforresult (Intent, 0); } @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { //match the corresponding intent if(requestcode==0&& resultcode==ACTIVITY.RESULT_OK) { //Get Data:uriUri uri=Data.getdata (); //Show PicturesToast.maketext ( This, Uri.getpath (), 100); } }
Android-intent applications