1、调用拨号程序:
1 // 给移动客服10086拨打电话 2 Uri uri = Uri.parse("tel:10086"); 3 Intent intent = new Intent(Intent.ACTION_DIAL, uri); 4 startActivity(intent);
2、调用彩信或短信:
1 // 给10086发送内容为“Hello”的短信 2 Uri uri = Uri.parse("smsto:10086"); 3 Intent intent = new Intent(Intent.ACTION_SENDTO, uri); 4 intent.putExtra("sms_body", "Hello"); 5 startActivity(intent); 6 // 发送彩信(相当于发送带附件的短信) 7 Intent intent = new Intent(Intent.ACTION_SEND); 8 intent.putExtra("sms_body", "Hello"); 9 Uri uri = Uri.parse("content://media/external/images/media/23"); 10 intent.putExtra(Intent.EXTRA_STREAM, uri); 11 intent.setType("image/png"); 12 startActivity(intent);
3、通过浏览器打开网页
1 // 打开Google主页 2 Uri uri = Uri.parse("http://www.google.com"); 3 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 4 startActivity(intent);
4、发送电子邮件
1 // 给someone@domain.com发邮件 2 Uri uri = Uri.parse("mailto:someone@domain.com"); 3 Intent intent = new Intent(Intent.ACTION_SENDTO, uri); 4 startActivity(intent); 5 // 给someone@domain.com发邮件发送内容为“Hello”的邮件 6 Intent intent = new Intent(Intent.ACTION_SEND); 7 intent.putExtra(Intent.EXTRA_EMAIL, "someone@domain.com"); 8 intent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 9 intent.putExtra(Intent.EXTRA_TEXT, "Hello"); 10 intent.setType("text/plain"); 11 startActivity(intent); 12 // 给多人发邮件 13 Intent intent=new Intent(Intent.ACTION_SEND); 14 String[] tos = {"1@abc.com", "2@abc.com"}; // 收件人 15 String[] ccs = {"3@abc.com", "4@abc.com"}; // 抄送 16 String[] bccs = {"5@abc.com", "6@abc.com"}; // 密送 17 intent.putExtra(Intent.EXTRA_EMAIL, tos); 18 intent.putExtra(Intent.EXTRA_CC, ccs); 19 intent.putExtra(Intent.EXTRA_BCC, bccs); 20 intent.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 21 intent.putExtra(Intent.EXTRA_TEXT, "Hello"); 22 intent.setType("message/rfc822"); 23 startActivity(intent);
5、显示地图路径及规划
1 // 打开Google地图中国北京位置(北纬39.9,东经116.3) 2 Uri uri = Uri.parse("geo:39.9,116.3"); 3 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 4 startActivity(intent); 5 // 路径规划:从北京某地(北纬39.9,东经116.3)到上海某地(北纬31.2,东经121.4) 6 Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4"); 7 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 8 startActivity(intent);
6、多媒体播放
1 Intent intent = new Intent(Intent.ACTION_VIEW); 2 Uri uri = Uri.parse("file:///sdcard/foo.mp3"); 3 intent.setDataAndType(uri, "audio/mp3"); 4 startActivity(intent); 5 6 Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); 7 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 8 startActivity(intent);
7、拍照
1 // 打开拍照程序 2 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 3 startActivityForResult(intent, 0); 4 // 取出照片数据 5 Bundle extras = intent.getExtras(); 6 Bitmap bitmap = (Bitmap) extras.get("data");
8、获取并裁剪图片
1 // 获取并剪切图片 2 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 3 intent.setType("image/*"); 4 intent.putExtra("crop", "true"); // 开启剪切 5 intent.putExtra("aspectX", 1); // 剪切的宽高比为1:2 6 intent.putExtra("aspectY", 2); 7 intent.putExtra("outputX", 20); // 保存图片的宽和高 8 intent.putExtra("outputY", 40); 9 intent.putExtra("output", Uri.fromFile(new File("/mnt/sdcard/temp"))); // 保存路径 10 intent.putExtra("outputFormat", "JPEG");// 返回格式 11 startActivityForResult(intent, 0); 12 // 剪切特定图片 13 Intent intent = new Intent("com.android.camera.action.CROP"); 14 intent.setClassName("com.android.camera", "com.android.camera.CropImage"); 15 intent.setData(Uri.fromFile(new File("/mnt/sdcard/temp"))); 16 intent.putExtra("outputX", 1); // 剪切的宽高比为1:2 17 intent.putExtra("outputY", 2); 18 intent.putExtra("aspectX", 20); // 保存图片的宽和高 19 intent.putExtra("aspectY", 40); 20 intent.putExtra("scale", true); 21 intent.putExtra("noFaceDetection", true); 22 intent.putExtra("output", Uri.parse("file:///mnt/sdcard/temp")); 23 startActivityForResult(intent, 0);
9、打开GOOGLE Market
1 // 打开Google Market直接进入该程序的详细页面 2 Uri uri = Uri.parse("market://details?id=" + "com.demo.app"); 3 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 4 startActivity(intent);
10、安装和卸载程序
1 Uri uri = Uri.fromParts("package", "com.demo.app", null); 2 Intent intent = new Intent(Intent.ACTION_DELETE, uri); 3 startActivity(intent);
11、进入设置界面
1 // 进入无线网络设置界面(其它可以举一反三) 2 Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); 3 startActivityForResult(intent, 0);