Android Intent 用法全面总结(转载)
1. [代码]调用拨号程序
|
1
2
3
4
|
// 给移动客服10086拨打电话Uri uri = Uri.parse("tel:10086");Intent intent = new Intent(Intent.ACTION_DIAL, uri);startActivity(intent); |
2. [代码]发送短信或彩信
|
1
2
3
4
5
6
7
8
9
10
11
12
|
// 给10086发送内容为“Hello”的短信Uri uri = Uri.parse("smsto:10086");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);intent.putExtra("sms_body", "Hello");startActivity(intent);// 发送彩信(相当于发送带附件的短信)Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra("sms_body", "Hello");Uri uri = Uri.parse("content://media/external/images/media/23");intent.putExtra(Intent.EXTRA_STREAM, uri);intent.setType("image/png");startActivity(intent); |
3. [代码]通过浏览器打开网页
|
1
2
3
4
|
// 打开Google主页Uri uri = Uri.parse("http://www.google.com");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent); |
4. [代码]发送电子邮件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// 给someone@domain.com发邮件Uri uri = Uri.parse("mailto:someone@domain.com");Intent intent = new Intent(Intent.ACTION_SENDTO, uri);startActivity(intent);// 给someone@domain.com发邮件发送内容为“Hello”的邮件Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_EMAIL, "someone@domain.com");intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");intent.putExtra(Intent.EXTRA_TEXT, "Hello");intent.setType("text/plain");startActivity(intent);// 给多人发邮件Intent intent=new Intent(Intent.ACTION_SEND);String[] tos = {"1@abc.com", "2@abc.com"}; // 收件人String[] ccs = {"3@abc.com", "4@abc.com"}; // 抄送String[] bccs = {"5@abc.com", "6@abc.com"}; // 密送intent.putExtra(Intent.EXTRA_EMAIL, tos);intent.putExtra(Intent.EXTRA_CC, ccs);intent.putExtra(Intent.EXTRA_BCC, bccs);intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");intent.putExtra(Intent.EXTRA_TEXT, "Hello");intent.setType("message/rfc822");startActivity(intent); |
5. [代码]显示地图与路径规划
|
1
2
3
4
5
6
7
8
|
// 打开Google地图中国北京位置(北纬39.9,东经116.3)Uri uri = Uri.parse("geo:39.9,116.3");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);// 路径规划:从北京某地(北纬39.9,东经116.3)到上海某地(北纬31.2,东经121.4)Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent); |
6. [代码]播放多媒体
|
1
2
3
4
5
6
7
8
|
Intent intent = new Intent(Intent.ACTION_VIEW);Uri uri = Uri.parse("file:///sdcard/foo.mp3");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); |
7. [代码]拍照
|
1
2
3
4
5
6
|
// 打开拍照程序Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0);// 取出照片数据Bundle extras = intent.getExtras(); Bitmap bitmap = (Bitmap) extras.get("data"); |
8. [代码]获取并剪切图片
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// 获取并剪切图片Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType("image/*");intent.putExtra("crop", "true"); // 开启剪切intent.putExtra("aspectX", 1); // 剪切的宽高比为1:2intent.putExtra("aspectY", 2);intent.putExtra("outputX", 20); // 保存图片的宽和高intent.putExtra("outputY", 40); intent.putExtra("output", Uri.fromFile(new File("/mnt/sdcard/temp"))); // 保存路径intent.putExtra("outputFormat", "JPEG");// 返回格式startActivityForResult(intent, 0);// 剪切特定图片Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.camera", "com.android.camera.CropImage"); intent.setData(Uri.fromFile(new File("/mnt/sdcard/temp"))); intent.putExtra("outputX", 1); // 剪切的宽高比为1:2intent.putExtra("outputY", 2);intent.putExtra("aspectX", 20); // 保存图片的宽和高intent.putExtra("aspectY", 40);intent.putExtra("scale", true);intent.putExtra("noFaceDetection", true); intent.putExtra("output", Uri.parse("file:///mnt/sdcard/temp")); startActivityForResult(intent, 0); |
9. [代码]打开Google Market
|
1
2
3
4
|
// 打开Google Market直接进入该程序的详细页面Uri uri = Uri.parse("market://details?id=" + "com.demo.app");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent); |
10. [代码]安装和卸载程序
|
1
2
3
|
Uri uri = Uri.fromParts("package", "com.demo.app", null); Intent intent = new Intent(Intent.ACTION_DELETE, uri); startActivity(intent); |
11. [代码]进入设置界面
|
1
2
3
|
// 进入无线网络设置界面(其它可以举一反三) Intent intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); startActivityForResult(intent, 0); |
Android Intent 用法全面总结(转载)的更多相关文章
- Android Intent 用法全面总结
[代码全屏查看]-Android Intent 用法全面总结 // [1].[代码] 调用拨号程序 跳至 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] / ...
- Android Intent用法总结
Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 ...
- android Bitmap用法总结(转载)
Bitmap用法总结1.Drawable → Bitmappublic static Bitmap drawableToBitmap(Drawable drawable) {Bitmap bitmap ...
- Android Intent的几种用法全面总结
Android Intent的几种用法全面总结 Intent, 用法 Intent应该算是Android中特有的东西.你可以在Intent中指定程序要执行的动作(比如:view,edit,dial), ...
- Android Intent机制与常见的用法
Activity Android于.Activity所有的程序都是必不可少,程都执行在Activity之中.Activity具有自己的生命周期(见http://www.cnblogs.com/feis ...
- android intent收集转载汇总
Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); ComponentName comp = ...
- Android组件系列----Intent详解(转载笔记)
[正文] Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重要. 一.什么是Intent 1.Intent的概念: Android中提供了Intent机制来协助应用 ...
- monkey测试===Android测试工具Monkey用法简介(转载)
Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力测试.Monkey ...
- android intent和intent action大全
1.Intent的用法:(1)用Action跳转1,使用Action跳转,如果有一个程序的AndroidManifest.xml中的某一个 Activity的IntentFilter段中 定义了包含了 ...
随机推荐
- android开发笔记之Volley (1)
1. volley的简介 Volley is an HTTP library that makes networking for Android apps easier and most import ...
- 在xcode5下利用Source Control 做 git 项目管理
xcode5做了很大的更新,其中一点非常实用的功能是集成了Source control项目管理,而且和git做了完美的结合:非常实用: 使用: 在新建项目时,选择 下面的 Create a git r ...
- Unity3d 录像
flashtd1: 回复 tqfa :我觉得是有方法可以实现的,之前使用高通的增强显示开发包时发现其实它是添加了一个类似movietexture的东西,叠加在它的摄像机上 如果文档里有操作moviet ...
- Android so文件生成
http://blog.csdn.net/laczff21/article/details/7542236 http://blog.csdn.net/yhm2046/article/details/8 ...
- javascript 将内容复制到剪贴板
javascript 将内容复制到剪贴板 CreateTime--2017年9月19日11:36:50 Author:Marydon js 操作剪贴板 1.设置剪贴板内容 UpdateTime-- ...
- JavaScript 中的string 方法
创建string的方法 var str ="abc"; var str = new String("abc"); var str = String(" ...
- 【SSH进阶之路】Struts基本原理 + 实现简单登录(二)
上面博文,主要简单的介绍了一下SSH的基本概念,比較宏观,作为刚開始学习的人可以有一个总体上的认识,个人觉得对学习有非常好的辅助功能.它不不过一个"瞭望塔".更是检验是否真正掌握全 ...
- 从源代码制作iDempiere Server安装软件(Ubuntu Desktop 12.04 LTS 64位)
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ 在Eclipse中寻找org.adempiere.server-feature项目 右击 ...
- Java教程到处都是,究竟怎样能学好Java?
学习Java如何入门?学习教程要点是什么?如何精通?做好以下这些点,入门更快,掌握Java更轻松. Java必备基础知识 1.你需要精通面向对象分析与设计(OOA/OOD).涉及模式(GOF,J2EE ...
- Android数据格式解析对象JSON用法
1.JSON概念: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性,从而可以在不同平台间进行数据交换.JSON采用兼容性很高的文本格式,同时也具备类似于C语言体系的行为. JSON可以将 ...