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