The first way, use action to jump.
1, use the action jump, if there is a program in the androidmanifest.xml of an activity in the Intentfilter segment defined contains the same action, then this intent with this target action match. If type,category is not defined in this intentfilter segment, then the activity is matched. But if you have more than two programs in your phone, a dialog box will pop up to show you the message.
The value of action has a lot of pre-defined in Android, and if you want to go directly to your own defined intent receiver, you can add a custom action value to the recipient's Intentfilter (and set the category value to " Android.intent.category.DEFAULT "), set the Action in your intent to intent, and you can jump directly to your own intent receiver. Because this action is unique in the system.
2,data/type, you can use URIs as data, such as URI uri = Uri.parse (http://www.google.com);
Intent i = new Intent (Intent.action_view,uri); During the Intent distribution of the cell phone, the data type is judged according to the http://www.google.com scheme.
The brower of the phone can match it, and in the intenfilter of the Brower manifest.xml there is the first Action_view Action, which can also handle the type of http:.
3, as for classification category, generally do not go to set it in intent, if you write intent receiver, in manifest.xml activity Intentfilter contains Android.category.DEFAULT So that all Intent that do not set the category (Intent.addcategory (String c);) will match this category.
4,extras (additional information), is a collection of all other additional information. You can use extras to provide extended information for your component, such as, if you want to perform the "Send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending component.
Java code package com.android.edit_text;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import android.view.KeyEvent;
Import Android.view.View;
Import Android.widget.EditText;
public class Myedittext extends Activity {
Private TextView M_textview;
Private EditText M_edittext;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
M_edittext = (EditText) This.findviewbyid (r.id.edittext01);
M_edittext.setonkeylistener (Edittextkeylistener);
}
Private Edittext.onkeylistener Edittextkeylistener = new Edittext.onkeylistener () {
@Override
public boolean OnKey (View arg0, int arg1, keyevent arg2) {
Action jump, you need to configure the action in Androidmanifest.xml
Intent i = new Intent ("Android.intent.action.mydialog");
MyEditText.this.startActivity (i);
return false;
}
};
}
Copy Code XML Code <?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.android.edit_text" android:versioncode= "1"
Android:versionname= "1.0" >
<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". Myedittext "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--configuration Jump activity-->
<activity android:name= "Com.android.dialog.MyDialog" >
<intent-filter>
<!--Configure the action path--
<action android:name= "Android.intent.action.mydialog"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
<USES-SDK android:minsdkversion= "7"/>
</manifest>
Copy the code the second way, jump with the class name.
Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the component. Intent is where the decoupling between the caller and the callee is implemented.
In the intent delivery process, the target consumer (another activity,intentreceiver or service) is found, that is, the responder of intent.
Java code Package COM. Android;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
public class Formstuff extends Activity {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.formstuff);
Final ImageButton button = (ImageButton) Findviewbyid (R.id.android_button);
Button.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
Jump with class name, need to declare activity in Androidmanifest.xml
Intent Intent = new Intent (formstuff.this, Hellotabwidget.class);
StartActivity (Intent);
}
});
}
Copy Code XML Code <?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "com. Android "android:versioncode=" 1 "android:versionname=" 1.0 ">
<application android:icon= "@drawable/icon" Android:theme= "@android: Style/theme.notitlebar" >
<activity android:name= ". Formstuff "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--statement activity-->
<activity android:name= "Hellotabwidget" ></activity>
</application>
<USES-SDK android:minsdkversion= "4"/>
</manifest>
Copy code Some of the intent common hair:
Java Code Display Web page
1. Uri uri = uri.parse ("http://google.com");
2. Intent it = new Intent (Intent.action_view, URI);
3. StartActivity (it);
Show Map
1. Uri uri = uri.parse ("geo:38.899533,-77.036476");
2. Intent it = new Intent (Intent.action_view, URI);
3. StartActivity (it);
4.//Other Geo URI examples
5.//geo:latitude,longitude
6.//geo:latitude,longitude?z=zoom
7.//geo:0,0?q=my+street+address
8.//geo:0,0?q=business+near+city
9.//google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapzoom
Path planning
1. Uri uri = Uri.parse ("Http://maps.google.com/maps?f=d&saddr=startLat Startlng&daddr=endlat endlng &hl=en ");
2. Intent it = new Intent (Intent.action_view, URI);
3. StartActivity (it);
4.//where Startlat, STARTLNG, Endlat, ENDLNG is a long with 6 decimals like:50.123456
Call
1.//Call out Dialer
2. Uri uri = uri.parse ("tel:0800000123");
3. Intent it = new Intent (intent.action_dial, URI);
4. StartActivity (it);
1.//Call out directly
2. Uri uri = uri.parse ("tel:0800000123");
3. Intent it = new Intent (Intent.action_call, URI);
4. StartActivity (it);
5.//Use this, to be in the Androidmanifest.xml, plus
6.//<uses-permission id= "Android.permission.CALL_PHONE"/>
Transfer Sms/mms
1.//Call SMS Program
2. Intent it = new Intent (Intent.action_view, URI);
3. It.putextra ("Sms_body", "The SMS Text");
4. It.settype ("vnd.android-dir/mms-sms");
5. StartActivity (IT);
1.//Send Message
2. Uri uri = uri.parse ("smsto://0800000123");
3. Intent it = new Intent (intent.action_sendto, URI);
4. It.putextra ("Sms_body", "The SMS Text");
5. StartActivity (IT);
1.//Transfer MMS
2. Uri uri = uri.parse ("Content://media/external/images/media/23");
3. Intent it = new Intent (intent.action_send);
4. It.putextra ("Sms_body", "some text");
5. It.putextra (Intent.extra_stream, URI);
6. It.settype ("Image/png");
7. StartActivity (IT);
Send email
1. Uri uri = uri.parse ("Mailto:[email protected]");
2. Intent it = new Intent (intent.action_sendto, URI);
3. StartActivity (it);
1. Intent it = new Intent (intent.action_send);
2. It.putextra (Intent.extra_email, "[EMAIL protected]");
3. It.putextra (Intent.extra_text, "The email body TEXT");
4. It.settype ("Text/plain");
5. StartActivity (Intent.createchooser (it, "Choose Email Client"));
1. Intent it=new Intent (intent.action_send);
2. string[] tos={"[Email protected]"};
3. string[] ccs={"[Email protected]"};
4. It.putextra (Intent.extra_email, TOS);
5. It.putextra (INTENT.EXTRA_CC, CCS);
6. It.putextra (Intent.extra_text, "The email body TEXT");
7. It.putextra (Intent.extra_subject, "The email SUBJECT text");
8. It.settype ("message/rfc822");
9. StartActivity (Intent.createchooser (it, "Choose Email Client"));
1.//Transfer Accessories
2. Intent it = new Intent (intent.action_send);
3. It.putextra (Intent.extra_subject, "The email SUBJECT text");
4. It.putextra (Intent.extra_stream, "File:///sdcard/mysong.mp3");
5. Sendintent.settype ("Audio/mp3");
6. StartActivity (Intent.createchooser (it, "Choose Email Client"));
Play Multimedia
Uri uri = uri.parse ("File:///sdcard/song.mp3");
Intent it = new Intent (Intent.action_view, URI);
It.settype ("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);
Market related
1.//Search for an application
2. Uri uri = uri.parse ("Market://search?q=pname:pkg_name");
3. Intent it = new Intent (Intent.action_view, URI);
4. StartActivity (it);
5.//where Pkg_name is the full package path for an application
1.//display information about an app
2. Uri uri = uri.parse ("market://details?id=app_id");
3. Intent it = new Intent (Intent.action_view, URI);
4. StartActivity (it);
5.//where app_id is the application ID, find the ID
6.//by clicking on your application in market home
7.//page, and notice the ID from the address bar
1. Uri uri = uri.fromparts ("package", strpackagename, NULL);
2. Intent it = new Intent (Intent.action_delete, URI);
3. StartActivity (it);
[Android] Intent How to implement page jumps [go]