手记

Intent隐式调用常用系统应用的Action和data

第一个参数是意图过滤器的Action,第二个参数是意图过滤器的data内容URI
Intent intent = new Intent(action, uri);

// 调用浏览器 

Uri webViewUri = Uri.parse("http://blog.csdn.net/zuolongsnail"); 

Intent intent = new Intent(Intent.ACTION_VIEW, webViewUri); 

// 调用地图 

Uri mapUri = Uri.parse("geo:100,100"); 

Intent intent = new Intent(Intent.ACTION_VIEW, mapUri); 

// 播放mp3 

Uri playUri = Uri.parse("file:///sdcard/test.mp3"); 

Intent intent = new Intent(Intent.ACTION_VIEW, playUri); 

intent.setDataAndType(playUri, "audio/mp3"); 

// 调用拨打电话 

Uri dialUri = Uri.parse("tel:10086"); 

Intent intent = new Intent(Intent.ACTION_DIAL, dialUri); 

// 直接拨打电话,需要加上权限<uses-permission id="android.permission.CALL_PHONE" /> 

Uri callUri = Uri.parse("tel:10086"); 

Intent intent = new Intent(Intent.ACTION_CALL, callUri); 

// 调用发邮件(这里要事先配置好的系统Email,否则是调不出发邮件界面的) 

Uri emailUri = Uri.parse("mailto:zuolongsnail@163.com"); 

Intent intent = new Intent(Intent.ACTION_SENDTO, emailUri); 

// 直接发邮件 

Intent intent = new Intent(Intent.ACTION_SEND); 

String[] tos = { "zuolongsnail@gmail.com" }; 

String[] ccs = { "zuolongsnail@163.com" }; 

intent.putExtra(Intent.EXTRA_EMAIL, tos); 

intent.putExtra(Intent.EXTRA_CC, ccs); 

intent.putExtra(Intent.EXTRA_TEXT, "the email text"); 

intent.putExtra(Intent.EXTRA_SUBJECT, "subject"); 

intent.setType("text/plain"); 

Intent.createChooser(intent, "Choose Email Client"); 

// 发短信 

Intent intent = new Intent(Intent.ACTION_VIEW); 

intent.putExtra("sms_body", "the sms text"); 

intent.setType("vnd.android-dir/mms-sms"); 

// 直接发短信 

Uri smsToUri = Uri.parse("smsto:10086"); 

Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri); 

intent.putExtra("sms_body", "the sms text"); 

// 发彩信 

Uri mmsUri = Uri.parse("content://media/external/images/media/23"); 

Intent intent = new Intent(Intent.ACTION_SEND); 

intent.putExtra("sms_body", "the sms text"); 

intent.putExtra(Intent.EXTRA_STREAM, mmsUri); 

intent.setType("image/png"); 

// 卸载应用 

Uri uninstallUri = Uri.fromParts("package", "com.app.test", null); 

Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri); 

// 安装应用 

Intent intent = new Intent(Intent.ACTION_VIEW); 

intent.setDataAndType(Uri.fromFile(new File("/sdcard/test.apk"), "application/vnd.android.package-archive"); 

// 在Android Market中查找应用 

Uri uri = Uri.parse("market://search?q=愤怒的小鸟");          

Intent intent = new Intent(Intent.ACTION_VIEW, uri);
1人推荐
随时随地看视频
慕课网APP