Android Program Development: (2) use Intent-2.5 use Intent to call built-in applications

Source: Internet
Author: User

We have learned how to call an activity in a single application. However, an important aspect in android development is to use intent to call the activity of other applications. In particular, your application can call many "built-in" applications in the system. The so-called "built-in" application refers to applications at the same level, such as Browser, Phone, and Sms. For example, if your application needs to open a webpage, you can use the Intent object to call the browser. The browser displays the webpage instead of creating a browser...
 
The following example shows how to call several commonly used "built-in" applications in the system.
 
 
1. Create a project called Intents.
 
Project directory:
 
 

 
 
2. Code in main. xml.
 
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
 
<Button
Android: id = "@ + id/btn_webbrowser"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: onClick = "onClickWebBrowser"
Android: text = "Web Browser"/>
 
<Button
Android: id = "@ + id/btn_makecils"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: onClick = "onclickmakecils"
Android: text = "Make CILS"/>
 
<Button
Android: id = "@ + id/btn_showMap"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: onClick = "onClickShowMap"
Android: text = "Show Map"/>
 
<Button
Android: id = "@ + id/btn_launchMyBrowser"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: onClick = "onClickLaunchMyBrowser"
Android: text = "Launch My Browser"/>
 
</LinearLayout>
3. The code in IntentsActivity. java. Package net. learn2develop. Intents;
 
Import android. app. Activity;
Import android. content. Intent;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. view. View;
 
Public class IntentsActivity extends Activity {
 
Int request_Code = 1;
 
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
}
 
Public void onClickWebBrowser (View view ){
Intent I = new Intent ("android. intent. action. VIEW ");
I. setData (Uri. parse ("http://www.amazon.com "));
StartActivity (I );
}
 
Public void onclickmakecils (View view ){
Intent I = new Intent (android. content. Intent. ACTION_DIAL,
Uri. parse ("tel: + 651234567 "));
StartActivity (I );
 
}
 
Public void onClickShowMap (View view ){
Intent I = new Intent (android. content. Intent. ACTION_VIEW,
Uri. parse ("geo: 37.827500,-122.481670 "));
StartActivity (I );
 
}
 
}
4. debugging.

 

:

After the program is started:





Click WebBrowser:

Click the makecils button:





Written by manoel
 

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.