14th, open other software via intent (Android)

Source: Internet
Author: User

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)

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.