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:2 intent.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:2 intent.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段中 定义了包含了 ...
随机推荐
- 最简单的方式用上https
1.在这个网站申请ssl证书 https://www.sslforfree.com 2.下载的证书使用这个脚本处理一下 #!/bin/bash HOST_NAME=$1 cp certificate. ...
- Mac触控板常用的手势操作
Mac触控板常用的手势操作 学习了:http://topbook.cc/archives/151 一个手指直接点击,类似Windows中鼠标左键功能,同时在苹果Safari等浏览器中,这个手势还 ...
- Set 遍历的三种方法
1.迭代遍历:Set<String> set = new HashSet<String>();Iterator<String> it = set.iterator( ...
- 2014ACM/ICPC亚洲区域赛牡丹江现场赛总结
不知道怎样说起-- 感觉还没那个比赛的感觉呢?如今就结束了. 9号.10号的时候学校还评比国奖.励志奖啥的,由于要来比赛,所以那些事情队友的国奖不能答辩.自己的励志奖班里乱搞要投票,自己又不在,真是无 ...
- jQuery li click失效问题
转自:http://blog.sina.com.cn/s/blog_64008ed70101nyoz.html 项目中使用到jQuery脚本插入一段代码,然后给代码加事件,但是click事件失效,网上 ...
- 在Eclipse中点击ctrl+h打开搜索界面,范围指定的项目中搜索包含person的文件
ctrl+h ===>File Search Tab ===>在containing text里输入person,scope ==>selected resources,搜索就可以了
- 超酷的实时颜色数据跟踪javascript类库 - Tracking.js
来源:GBin1.com 今天介绍这款超棒的Javascript类库是 - Tracking.js,它能够独立不依赖第三方类库帮助开发人员动态跟踪摄像头输出相关数据. 这些数据包括了颜色或者是人, 这 ...
- SQL Server中按照条件随机返回数据
需求:查询对应关键字的数据,并随机返回一条. 这时,需要一个SQL的那只方法:NEWID(). 用法: [sql]SELECT TOP 1 * FROM Table WHERE TID = 1 ORD ...
- swift 使用匿名函数初始化属性
swift 使用匿名函数初始化属性 匿名函数格式: { //代码体 }() 大括号是定义函数体的,小括号()是调用函数体的. 为什么不写一个函数然后调用函数呢?为何用匿名函数呢? 主要还是代码的简洁性 ...
- 蓝的成长记——追逐DBA(6): 做事与做人:小技术,大为人
***********************************************声明*************************************************** ...