public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } // 打電話 public void call(View view) { Intent intent = new Intent(); intent.setAction(intent.ACTION_CALL); // intent.setAction("android.intent.action.CALL"); // 如下各項皆如此,都有兩種寫法。 intent.setData(Uri.parse("tel:10086")); startActivity(intent); } // 調用撥號面板: public void dial(View view) { Intent intent = new Intent(); intent.setAction(intent.ACTION_DIAL); intent.setData(Uri.parse("tel:10086")); startActivity(intent); } // 利用 Uri 打開瀏覽器、打開地圖等: public void page(View view) { // Uri uri = Uri.parse("http://www.google.com"); // 瀏覽器 Uri uri = Uri.parse("geo:39.899533,116.036476"); // 打開地圖定位 Intent intent = new Intent(); intent.setAction(intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } // 打開視頻 public void video(View view) { Intent intent = new Intent(); Uri uri = Uri.parse("/mnt/sdcard/papa.mp4"); intent.setDataAndType(uri, "video/*"); startActivity(intent); } // 打開發送短信的程序 public void sms(View view) { Intent intent = new Intent(); intent.setAction(intent.ACTION_VIEW); intent.setType("vnd.android-dir/mms-sms"); intent.putExtra("sms_body", "短信內容"); startActivity(intent); } // 發送短信 public void send(View view) { Uri uri = Uri.parse("smsto:10086"); Intent intent = new Intent(); intent.setAction(intent.ACTION_SENDTO); intent.setData(uri); intent.putExtra("sms_body", "短信內容"); startActivity(intent); } // 發送彩信 , 設備會提示選擇合適的程序發送 public void sendcai(View view) { Uri uri = Uri.parse("/mnt/sdcard/aaa.png"); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("image/png"); intent.putExtra("sms_body", " 內容 "); intent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(intent); } // 打開系統的wifi public void wifi(View view) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_WIRELESS_SETTINGS); startActivity(intent); } // 打開系統的聲音設置 public void voice(View view) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_SOUND_SETTINGS); startActivity(intent); } // 返回主界面 public void openhome(View view) { Intent intent = new Intent(); intent.setAction(intent.ACTION_MAIN); intent.addCategory(intent.CATEGORY_HOME); startActivity(intent); } // 打開系統的圖片 public void openimage(View view) { Intent intent = new Intent(); intent.setAction(intent.ACTION_VIEW); // 若是data和type同時存在,不要分開設置 intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/papa.jsg")), "image/*"); /* * intent.setData(Uri.fromFile(new File("/mnt/sdcard/papa.mp4"))); * intent.setType("video/*"); */ startActivity(intent); } }