android Intent的用法总结(应用的卸载、安装)

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);


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值