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段中 定义了包含了 ...
随机推荐
- 谈谈WEB开发跟非WEB开发各自不同的关注点
何为非WEB开发呢,个人理解就是不是用浏览器打开的应用统称为非WEB开发,抽象讲可以理解成C/S模式. WEB开发,技术人员的积累在如下几个方面: HTML + CSS + JavaScript 各种 ...
- android开发笔记之Volley (1)
1. volley的简介 Volley is an HTTP library that makes networking for Android apps easier and most import ...
- CEdit自动换行和状态栏添加
CEdit自动换行在对话框的属性中是可以直接设置的. Auto HScroll设置为False Auto VScroll设置为True Mulitline设置为True Want Return设置为T ...
- Centos 7 通过yum的方式安装配置Artifactory 5.10
制品仓库系统有很多,例如:Artifactory,Nexus,Archiva, 其中Artifactory拥有很多强大的企业级特性和人性化的用户接口,很多大型的公司都在使用它. 背景:因客户需求,需要 ...
- 在retrofit+Rxjava中如何取得状态码非200(出现错误)时的response里的body
一个典型的retrofit+Rxjava的网络请求如下 Subscription subscription = videoChartService.login(newBody) .observeOn( ...
- 设计模式 - 迭代器模式(iterator pattern) 具体解释
迭代器模式(iterator pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 迭代器模式(iterator pattern) : 提供一 ...
- Windows进程通信 -- 共享内存
享内存的方式原理就是将一份物理内存映射到不同进程各自的虚拟地址空间上,这样每个进程都可以读取同一份数据,从而实现进程通信.因为是通过内存操作实现通信,因此是一种最高效的数据交换方法. 共享内存在 Wi ...
- Python/MOOC /翻Wall和互联网编程的那些事
Python MOOC 翻Wall和互联网编程的那些事 声明: 1)本报告由博客园bitpeach撰写,版权所有,免费转载,请注明出处,并请勿作商业用途. 2)若本文档内有侵权文字或图片等内容,请联系 ...
- 【Linux】通过传入变量进行数学运算
一个简单的sum求和 #! /bin/bash ## For get the sum of tow numbers ## Writen by Qinys ## Date:2018-06-26 a=1 ...
- MySQL数据迁移问题
最近尝试了一下小型数据迁移.本地迁移,windows平台,修改配置文件中的data_dir项,然后将旧的data文件下的数据文件全部拷贝过去. 之后登陆数据库,竟然1145错误.可以看到数据库的结构, ...