Intent是android中特有的一个东西,我们可以个Intent指定特定的动作,然后调用startActivity()执行该动作。
1、显示网页:
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW,intent);
startActivity(intent);
2、显示地图
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
3、路径规划
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
4、拨号盘
Uri uri = Uri.parse("tel:13317490705");
Intent intent = new Intent(Intent.ACTION_DIAL,uri);
startActivity(intent);
5、打电话
Uri uri = Uri.parse("tes.13317490705");
Intent intent = new Intent(Intent.ACTION_CALL,uri);
startActivity(intent);
6、调用系统发送短信
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body","The Sms Text");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
7、发送短信
Uri uri = Uri.parse("smsto:13317490705");
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body","这是发给13317490705的短信");
startActivity(intent);
8、发送彩信
Uri uri = Uri.parse("content://media/external/images/media/1");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body","这是彩信。。。");
intent.putExtra(Intent.EXTRA_STREAM,uri);
intent.setType("image/png");
startActivity(intent);
9、发送Email
uri uri = Uri.parse("mailto:690124004@qq.com");
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL,"690124004@qq.com");
intent.putExtra(Intent.EXTRA_TEXT,"this is send to 690124004 email");
intent.setType("text/plain");
startActivity(Intent.createChooser(intent,"Choose Email Client"));
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = {"690124004@qq.com"};
String[] ccs = {"690124005@qq.com"};
intent.putExtra(Intent.EXTRA_EMAIL,tos);
intnet.putExtra(Intent.EXTRA_CC,ccs);
intent.putExtra(Intent.EXTRA_TEXT,"this is email body text...");
intent.putExtra(Intent.EXTRA_SUBJECT,"this is email subject text");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent,"Choose Email Client"));
10、添加附件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT,"This is subject...");
intent.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/kugou/download/it is ok.mp3");
intent.setType("audio/mp3");
startActivity(Intent.createChooser(intent,"Choose File Client"));
11、播放音乐
Uri uri = Uri.parse("file:///sdcard/kugou/download/trouble is friend.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri,"audio/mp3");
startActivity(intent);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
12、卸载应用
Uri uri = Uri.fromParts("package",strPackageName,null);
Intent intent = new Intent(Intent.ACTION_DELETE,uri);
startActivity(intent);
Uri uri = Uri.parse("package:com.yx.firstApp");
Intent intent = new Intent(Intent.ACTION_DELETE);
startActivity(intent);
13、安装应用
Uri uri = Uri.fromFile(installFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri,"application/vnd.android.package-archive");
startActivity(intent);