intent 使用集合

Android中,Intent是一个将要执行的动作的抽象的描述,一般来说是作为参数来使用,由Intent来协助完成android各个组件之间的通讯。以下列出Intent常用的用法:

1、调用WEB浏览器

[java]  view plain copy
  1. Uri uri = Uri.parse("http://www.baidu.com");   
  2. Intent intent = new Intent(Intent.ACTION_VIEW ,uri);   
  3. startActivity(intent);   

2、在地图上显示某个坐标

[java]  view plain copy
  1. Uri uri = Uri.parse("geo:21.803233,-53.829831");   
  2. Intent intent = new Intent(Intent.Action_VIEW, uri);   
  3. startActivity(intent);   

3、显示路径

[java]  view plain copy
  1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");   
  2. Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
  3. startActivity(intent);  

4、调用拨打电话界面

[java]  view plain copy
  1. Uri uri = Uri.parse("tel:10086");   
  2. Intent intent = new Intent(Intent.ACTION_DIAL, uri);   
  3. startActivity(intent);   

5、直接拨打电话

需要添加权限 

<uses-permission id="android.permission.CALL_PHONE" />

[java]  view plain copy
  1. Uri uri = Uri.parse("tel.10086");   
  2. Intent intent =new Intent(Intent.ACTION_CALL, uri);  

6发送短信或彩信

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_VIEW);   
  2. intent.putExtra("sms_body""The SMS text");   
  3. intent.setType("vnd.android-dir/mms-sms");   
  4. startActivity(intent);  

7、发送短信

[java]  view plain copy
  1. Uri uri = Uri.parse("smsto:10000");   
  2. Intent intent = new Intent(Intent.ACTION_SENDTO, uri);   
  3. intent.putExtra("sms_body""haha");   
  4. startActivity(intent);   

8、发送彩信

[java]  view plain copy
  1. Uri uri = Uri.parse("content://media/external/images/media/23");   
  2. Intent intent = new Intent(Intent.ACTION_SEND);   
  3. intent.putExtra("sms_body""some text");   
  4. intent.putExtra(Intent.EXTRA_STREAM, uri);   
  5. intent.setType("image/png");   
  6. startActivity(intent);   

或者

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_SEND);   
  2. intent.setClassName("com.android.mms""com.android.mms.ui.ComposeMessageActivity");   
  3. intent.putExtra("subject""彩信主题");   
  4. intent.putExtra("sms_body""彩信内容");   
  5. intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/images/11.jpg"));   
  6. intent.setType("image/jpeg");   
  7. startActivity(intent);   

9、调用发送邮件功能

[java]  view plain copy
  1. Uri uri = Uri.parse("mailto:xxx@foxmail.com");   
  2. Intent intent = new Intent(Intent.ACTION_SENDTO, uri);   
  3. startActivity(intent);  

10、发送邮件

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_SEND);   
  2. intent.putExtra(Intent.EXTRA_EMAIL, xxx@foxmail.com);   
  3. intent.putExtra(Intent.EXTRA_TEXT, "The email body text");   
  4. intent.setType("text/plain");   
  5. startActivity(Intent.createChooser(intent, "Choose Email Client"));  

或者

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_SEND);   
  2. String[] tos = {"me@abc.com"};   
  3. String[] ccs = {"you@abc.com"};   
  4. intent.putExtra(Intent.EXTRA_EMAIL, tos);   
  5. intent.putExtra(Intent.EXTRA_CC, ccs);   
  6. intent.putExtra(Intent.EXTRA_TEXT, "The email body text");   
  7. intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
  8. intent.setType("message/rfc822");   
  9. startActivity(Intent.createChooser(intent, "Choose Email Client"));   

11、播放媒体文件

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_VIEW);   
  2. Uri uri = Uri.parse(<a href="file:///sdcard/musics/someonelikeyou.mp3">file:///sdcard/musics/someonelikeyou.mp3</a>);   
  3. intent.setDataAndType(uri, "audio/mp3");   
  4. startActivity(intent);   
  5. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
  6. Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
  7. startActivity(intent);  

12、卸载APK

[java]  view plain copy
  1. Uri uri = Uri.fromParts("package", strPackageName, null);   
  2. Intent intent = new Intent(Intent.ACTION_DELETE, uri);   
  3. startActivity(intent);   

或者

[java]  view plain copy
  1. Uri uninstallUri = Uri.fromParts("package""xxx"null);   
  2. Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri);   

13、安装APK

[java]  view plain copy
  1. Uri installUri = Uri.fromParts("package""xxx"null);   
  2. Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);  

 14、播放音乐

[java]  view plain copy
  1. Uri playUri = Uri.parse("file:///sdcard/download/sth.mp3");   
  2. Intent intent = new Intent(Intent.ACTION_VIEW, playUri);   

15、发送附件

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_SEND);   
  2. intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
  3. intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/test.mp3");   
  4. sendIntent.setType("audio/mp3");   
  5. startActivity(Intent.createChooser(intent, "Choose Email Client"));   

16market上某个应用信,pkg_name就是应用的packageName

[java]  view plain copy
  1. Uri uri = Uri.parse("market://search?q=pname:pkg_name");   
  2. Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
  3. startActivity(intent);   

17market上某个应用信息,app_id可以通过www网站看下

[java]  view plain copy
  1. Uri uri = Uri.parse("market://details?id=app_id");   
  2. Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
  3. startActivity(intent);   

18、调用搜索功能

[java]  view plain copy
  1. Intent intent = new Intent();   
  2. intent.setAction(Intent.ACTION_WEB_SEARCH);   
  3. intent.putExtra(SearchManager.QUERY, "android");   
  4. startActivity(intent);  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值