Activity_main.xml
<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:orientation= "vertical" tools:context= ". Mainactivity "> <button android:id=" @+id/main_web " android:layout_width=" Match_parent " android:layout_height= "Wrap_content" android:text= "Web"/> <button android:id= "@+id/main_ Tel " android:layout_width=" match_parent " android:layout_height=" wrap_content " android:text=" tel "/></linearlayout>
Mainactivity.java
Package Com.example.demo0623;import Android.app.activity;import Android.content.intent;import Android.net.Uri; Import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;public class Mainactivity extends Activity implements Onclicklistener {private Button main_web, Main_tel; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate);//Remove title requestwindowfeature (window.feature_no_title); SetContentView ( R.layout.activity_main);//Initialize control Initview ();} private void Initview () {//TODO auto-generated method stubmain_web = (Button) This.findviewbyid (r.id.main_web); Main_tel = (Button) This.findviewbyid (R.id.main_tel); Main_web.setonclicklistener (this); Main_tel.setonclicklistener (this);} Click event @overridepublic void OnClick (View arg0) {//Jump to Browser open Baiduif (arg0.getid () = = R.id.main_web) {Intent Intent = new I Ntent (Intent.action_view); Intent.setdata (Uri.parse ("http://www.baidu.com")); StartActivity (intent);//Jump To dial number page} else if (arg0.getid () = = R.id.main_tel) {Intent intent = new Intent (Intent.action_d IAL); Intent.setdata (Uri.parse ("tel:10086")); StartActivity (intent);}}
Run:
Click Web
Click Tel
14th, open other software via intent (Android)