Android Studio Intent An implicit startup, texting, dialing, calling, accessing Web pages, and other instance code _android

Source: Internet
Author: User
Tags xmlns

Android Studio Intent An implicit start, texting, dialing, calling, accessing a Web page, and other instance code

Function

Create 5 buttons, implicitly start, text message, dial button, phone button, open Web button. By using intent to complete the functions under the respective buttons

The code directory is as follows

The detailed code is as follows:

The Activity_main.xml code is as follows

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http:// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:o" rientation= "Horizontal" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen Activity_horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen Activity_vertical_margin "tools:context=". Mainactivity "> <linearlayout android:layout_width=" 0dp "android:layout_height=" Wrap_content "Android: layout_weight= "1" android:orientation= "vertical" > <button android:id= "@+id/button1" Android:lay
      Out_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Implicit startup"/> Android:id= "@+id/button2" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Andro id:text= "Texting"/> &Lt Button android:id= "@+id/button3" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" "Android:text=" dial button "/> <button android:id=" @+id/button4 "android:layout_width=" wrap_content
    "Android:layout_height=" wrap_content "android:text=" phone button "/> </LinearLayout> <linearlayout
      Android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "2" > <Button Android:id= "@+id/button5" android:layout_width= "match_parent" android:layout_height= "192DP" Android : text= "open Baidu Web page"/> </LinearLayout> </LinearLayout>

The Firstlayout.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
  android:layout_width=" match_parent "
  android:layout_height=" match_parent "
  android:o" rientation= "vertical" >
  <edittext
    android:id= "@+id/edittext1" android:layout_width= "Match_"
    Parent "
    android:layout_height=" match_parent "
    android:text=" This is the second interface "/>

</LinearLayout>

The Mainactivity.java code is as follows:

Package Com.example.administrator.chang;
Import android.app.Activity;
Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.view.View;

Import Android.widget.Button; public class Mainactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Super
    . OnCreate (Savedinstancestate);

    Setcontentview (R.layout.activity_main);
    Button button1= (button) Findviewbyid (R.id.button1);  Button1.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {Intent
        Intent =new Intent ("Com.example.administrator.chang.ACTION_START");
      StartActivity (Intent);
    }
    });
    Send SMS button button2= (button) Findviewbyid (R.id.button2);  Button2.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {Intent
        Intent = new Intent ();
        Intent.setaction (intent.action_sendto); Intent.setdata (URI.PArse ("smsto:10086"));
        Intent.putextra ("Sms_body", "The SMS Text");
      StartActivity (Intent);
    }
    });
    Dialing button button3= (button) Findviewbyid (R.id.button3);  Button3.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {Intent
        Intent =new Intent ();
        Intent.setaction (intent.action_dial);
        Intent.setdata (Uri.parse ("tel:10086"));
      StartActivity (Intent);
    }
    });
    Call button button4= (button) Findviewbyid (R.ID.BUTTON4);  Button4.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {Intent
        Intent=new Intent ();
        Intent.setaction (Intent.action_call);
        Intent.setdata (Uri.parse ("tel:10086"));
      StartActivity (Intent);

    }
    });
    Button button5= (button) Findviewbyid (R.ID.BUTTON5); Button5.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View V) {Intent intent=new Intent ();
        Intent.setaction (Intent.action_view);
        Intent.setdata (Uri.parse ("http://www.baidu.com"));
      StartActivity (Intent);

  }
    }); }


}

The Secondactivity.java code is as follows:

Package Com.example.administrator.chang;

Import android.app.Activity;
Import Android.os.Bundle;

/**
 * Created by the Administrator on 2015/8/19
 . *
/public class Secondactivity extends activity {
  @Override
  protected void OnCreate (Bundle Savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.firstlayout);
  }

The Androidmanifest.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/" Android "package=" Com.example.administrator.chang "> <uses-permission android:name=" android.permission.CALL_ PHONE "/> <application android:allowbackup=" true "android:icon=" @mipmap/ic_launcher "android:label=" @s Tring/app_name "Android:theme=" @style/apptheme "> <activity android:name=". Mainactivity "android:label=" @string/app_name "> <intent-filter> <action android:name=" Andr Oid.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </inten t-filter> </activity> <activity android:name= ". Secondactivity "> <intent-filter> <action android:name=" Com.example.administrator.chang.ACTION_ST ART "/> <category android:name=" Android.intent.category.DEFAULT "/> </intent-filter> < /Activity> </application> </manifest> 

Description: The call button needs to add user rights, the specific code part is

<uses-permission android:name= "Android.permission.CALL_PHONE"/> Texting
button I used Intent.setaction ( INTENT.ACTION_SENDTO); If you can send a message directly, you need to add user rights
Android.permission.SEND_SMS

Strict case sensitivity in Android. For example, the following two sections of code represent different meanings:

<categoryandroid:name= "Android.intent.category.LAUNCHER"/>

 <category android:name= "Android. INTENT. CATEGORY. LAUNCHER "/>

The results are as follows:

Main Page:

Click on an implicit start to jump to the second page

Click Send SMS jump to send SMS page

Click on the dialing button to jump to the system dial interface

Click on the phone button to jump to the call interface

Click to open Baidu Page button to jump to Baidu website

Thank you for reading, I hope to help you, thank you for your support for this site!

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.