The Android tutorial Intent the action attribute using the example (intent texting) _android

Source: Internet
Author: User

Action: A string constant that sets the action to be completed by intent. Use Setaction () to set the Action property and use Getaction () to get the Action property. You can either use the system's built-in action or define it yourself. System custom ACTION, such as Action_view, Action_edit, Action_main, and so on.

1. Custom Action

Specify an action constant in the androidmanifest.xml of the destination activity.

Copy Code code as follows:

<activity android:name= ". Actiondestination ">
<intent-filter>
<action android:name= "Skywang_action"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

The role of the <categoryandroid:name= "Android.intent.category.DEFAULT"/> is to illustrate that an implicit jump can be made by calling Setaction ("Skywang_ ACTION ") to find actiondestination this activity. In this way, other classes can jump to actiondestination through the following code. When you jump, the setaction string "skywang_action" must be consistent with the "skywang_action" defined in Androidmanifest.xml.
Copy Code code as follows:

Intent Intent = new Intent ();
Intent.setaction ("Skywang_action");
StartActivity (Intent);

2 system action

Copy Code code as follows:

Traffic Web page
URI Uri =uri.parse ("http://www.baidu.com");
Intent Intent = newintent (Intent.action_view, URI);
StartActivity (Intent);
Dial number
If you are want to use action_dial, your mustadd permissin in manifest, the permission is bellow
<uses-permissionandroid:name= "Android.permission.CALL_PHONE"/>
Uri uri = uri.parse ("tel:12580");
Intent it = new Intent (Intent.action_dial,uri);
StartActivity (IT);
Send SMS
Uri uri = uri.parse ("smsto:13410177756");
Intent it = newintent (Intent.action_sendto, URI);
It.putextra ("Sms_body", "thesms text");
StartActivity (IT);
Play mp3
Intent it = new Intent (Intent.action_view);
URI Uri =uri.parse ("File:///sdcard/song.mp3");
It.setdataandtype (URI, "Audio/mp3");
StartActivity (IT);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.