ITEEDU

用Intent调用系统中经常被用到的组件

web浏览器

Uri uri= Uri.parse("http://www.iteedu.com");
Intent it  = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

地图

Uri mapUri = Uri.parse("geo:38.899533,-77.036476");
Intent it  = new Intent(Intent.ACTION_VIEW, mapUri);
startActivity(it);

调拨打电话界面

叫出拨号程序

Uri telUri = Uri.parse("tel:100861");
Intent it  = new Intent(Intent.ACTION_DIAL, telUri);
startActivity(it);

直接拨打电话

直接打电话出去

Uri callUri = Uri.parse("tel:100861");
Intent it  = new Intent(Intent.ACTION_CALL, callUri);
startActivity(it);
//用這个,要在 AndroidManifest.xml 中,加上   
//<uses-permission id="android.permission.CALL_PHONE" />>

卸载

Uri uninstallUri = Uri.fromParts("package", "xxx", null);
Intent it  = new Intent(Intent.ACTION_DELETE, uninstallUri);
startActivity(it);

安装

Uri installUri = Uri.fromParts("package", "xxx", null);
Intent it  = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
startActivity(it);

播放

Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
Intent it = new Intent(Intent.ACTION_VIEW, playUri);
startActivity(it);

调用邮件程序

Uri emailUri = Uri.parse("mailto:me@abc.com");
Intent it  = new Intent(Intent.ACTION_SENDTO, emailUri);
startActivity(it);

发邮件

//方法一
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
it.putExtra(Intent.EXTRA_TEXT, "iteedu.com");   
it.setType("text/plain");   
startActivity(Intent.createChooser(it, "Choose Email Client"));  
//方法二
Intent it  = new Intent(Intent.ACTION_SEND);
String[] tos = { "me@abc.com" };
String[] ccs = { "me@abc.com" };
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "body");
it.putExtra(Intent.EXTRA_SUBJECT, "iteedu");
it.setType("message/rfc882");
Intent.createChooser(returnIt, "Choose Email Client");
startActivity(it);

发短信

Uri smsUri = Uri.parse("tel:100861");
Intent it= new Intent(Intent.ACTION_VIEW, smsUri);
it.putExtra("sms_body", "iteedu.com");
it.setType("vnd.android-dir/mms-sms");    
startActivity(it);

发彩信

Uri mmsUri = Uri.parse("content://media/external/images/media/23");
Intent it= new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "iteedu.com");
it.putExtra(Intent.EXTRA_STREAM, mmsUri);
it.setType("image/png");
startActivity(it);