Getting Started with Android Development (ii) using intent 2.5 to invoke a built-in application with intent

Source: Internet
Author: User


We've learned how to invoke an activity in a single application of our own. However, one of the more important developments in Android is the use of intent to invoke other application activity. In particular, your application can invoke many "built-in" applications in the system. The so-called "built-in" application, refers to the same level of application, such as browser,phone,sms and so on. For example, if your application needs to open a Web page, you can use the intent object to invoke the browser, and the browser will display the page instead of creating a browser of its own ...



The following example shows how to invoke several of the more commonly used "built-in" applications in the system.



1. Create a project, Intents.



2. Code in the 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=" vertic Al "> 
<button android:id=" @+id/btn_webbrowser "android:layout_width=" fill_p Arent "android:layout_height=" wrap_content "android:onclick=" Onclickwebbrowser "android:text=" W EB Browser "/> 
<button android:id=" @+id/btn_makecalls "Android:layout_width" = "Fill_parent" android:layout_height= "wrap_content" android:onclick= "Onclickmakecalls" Android: text= "Make Calls"/> 
<button android:id= "@+id/btn_showmap" Android:layout_w Idth= "Fill_parent" android:layout_height= "wrap_content" android:onclick= "Onclickshowmap" Androi     D:text= "Show Map"/>
         
    <button android:id= "@+id/btn_launchmybrowser" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:onclick= "Onclicklaunchmybrowser" android:text= "Laun" ch my Browser "/> </LinearLayout>

The code in

3. Intentsactivity.java.


public class Intentsactivity extends activity {int request_code = 1; /** called the activity is a.     
        * * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);     
    Setcontentview (R.layout.main); The 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 Onclickmakecalls (view view) {Intent i = new Intent (android.content.intent.a     
        Ction_dial, Uri.parse ("tel:+651234567"));     
         
    StartActivity (i); public void Onclickshowmap (view view) {Intent i = new Intent (Android.content.Intent.ACT     
   Ion_view, Uri.parse ("geo:37.827500,-122.481670"));     StartActivity (i); }     
         
}


4. Debugging.



After the program is started:








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.