Chapter 4 open other software (Android) through Intent)

Source: Internet
Author: User

Chapter 4 open other software (Android) through Intent)

Activity_main.xml

 

 
  
  
 

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 the title requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. activity_main); // initialization 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 the browser and open baiduif (arg0.getId () = R. id. main_web) {Intent intent = new Intent (Intent. ACTION_VIEW); intent. setData (Uri. parse ("http://www.baidu.com"); startActivity (intent); // jump to the dialing page} else if (arg0.getId () = R. id. main_tel) {Intent intent = new Intent (Intent. ACTION_DIAL); intent. setData (Uri. parse ("tel: 10086"); startActivity (intent );}}}

 

Run:

Click web

Click tel

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.