Android Intent 用法全面总结
来源:互联网 发布:madness官网和淘宝代购 编辑:程序博客网 时间:2024/05/01 20:21
[代码] 调用拨号程序
1
// 给移动客服10086拨打电话
2
Uri uri = Uri.parse(
"tel:10086"
);
3
Intent intent =
new
Intent(Intent.ACTION_DIAL, uri);
4
startActivity(intent);
[代码] 发送短信或彩信
01
// 给10086发送内容为“Hello”的短信
02
Uri uri = Uri.parse(
"smsto:10086"
);
03
Intent intent =
new
Intent(Intent.ACTION_SENDTO, uri);
04
intent.putExtra(
"sms_body"
,
"Hello"
);
05
startActivity(intent);
06
// 发送彩信(相当于发送带附件的短信)
07
Intent intent =
new
Intent(Intent.ACTION_SEND);
08
intent.putExtra(
"sms_body"
,
"Hello"
);
09
Uri uri = Uri.parse(
"content://media/external/images/media/23"
);
10
intent.putExtra(Intent.EXTRA_STREAM, uri);
11
intent.setType(
"image/png"
);
12
startActivity(intent);
[代码] 通过浏览器打开网页
1
// 打开Google主页
2
Uri uri = Uri.parse(
"http://www.google.com"
);
3
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
4
startActivity(intent);
[代码] 发送电子邮件
01
// 给someone@domain.com发邮件
02
Uri uri = Uri.parse(
"mailto:someone@domain.com"
);
03
Intent intent =
new
Intent(Intent.ACTION_SENDTO, uri);
04
startActivity(intent);
05
// 给someone@domain.com发邮件发送内容为“Hello”的邮件
06
Intent intent =
new
Intent(Intent.ACTION_SEND);
07
intent.putExtra(Intent.EXTRA_EMAIL,
"someone@domain.com"
);
08
intent.putExtra(Intent.EXTRA_SUBJECT,
"Subject"
);
09
intent.putExtra(Intent.EXTRA_TEXT,
"Hello"
);
10
intent.setType(
"text/plain"
);
11
startActivity(intent);
12
// 给多人发邮件
13
Intent intent=
new
Intent(Intent.ACTION_SEND);
14
String[] tos = {
"1@abc.com"
,
"2@abc.com"
};
// 收件人
15
String[] ccs = {
"3@abc.com"
,
"4@abc.com"
};
// 抄送
16
String[] bccs = {
"5@abc.com"
,
"6@abc.com"
};
// 密送
17
intent.putExtra(Intent.EXTRA_EMAIL, tos);
18
intent.putExtra(Intent.EXTRA_CC, ccs);
19
intent.putExtra(Intent.EXTRA_BCC, bccs);
20
intent.putExtra(Intent.EXTRA_SUBJECT,
"Subject"
);
21
intent.putExtra(Intent.EXTRA_TEXT,
"Hello"
);
22
intent.setType(
"message/rfc822"
);
23
startActivity(intent);
[代码] 显示地图与路径规划
1
// 打开Google地图中国北京位置(北纬39.9,东经116.3)
2
Uri uri = Uri.parse(
"geo:39.9,116.3"
);
3
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
4
startActivity(intent);
5
// 路径规划:从北京某地(北纬39.9,东经116.3)到上海某地(北纬31.2,东经121.4)
6
Uri uri = Uri.parse(
"http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4"
);
7
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
8
startActivity(intent);
[代码] 播放多媒体
1
Intent intent =
new
Intent(Intent.ACTION_VIEW);
2
Uri uri = Uri.parse(
"file:///sdcard/foo.mp3"
);
3
intent.setDataAndType(uri,
"audio/mp3"
);
4
startActivity(intent);
5
6
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,
"1"
);
7
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
8
startActivity(intent);
[代码] 拍照
1
// 打开拍照程序
2
Intent intent =
new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
3
startActivityForResult(intent,
0
);
4
// 取出照片数据
5
Bundle extras = intent.getExtras();
6
Bitmap bitmap = (Bitmap) extras.get(
"data"
);
[代码] 获取并剪切图片
01
// 获取并剪切图片
02
Intent intent =
new
Intent(Intent.ACTION_GET_CONTENT);
03
intent.setType(
"image/*"
);
04
intent.putExtra(
"crop"
,
"true"
);
// 开启剪切
05
intent.putExtra(
"aspectX"
,
1
);
// 剪切的宽高比为1:2
06
intent.putExtra(
"aspectY"
,
2
);
07
intent.putExtra(
"outputX"
,
20
);
// 保存图片的宽和高
08
intent.putExtra(
"outputY"
,
40
);
09
intent.putExtra(
"output"
, Uri.fromFile(
new
File(
"/mnt/sdcard/temp"
)));
// 保存路径
10
intent.putExtra(
"outputFormat"
,
"JPEG"
);
// 返回格式
11
startActivityForResult(intent,
0
);
12
// 剪切特定图片
13
Intent intent =
new
Intent(
"com.android.camera.action.CROP"
);
14
intent.setClassName(
"com.android.camera"
,
"com.android.camera.CropImage"
);
15
intent.setData(Uri.fromFile(
new
File(
"/mnt/sdcard/temp"
)));
16
intent.putExtra(
"outputX"
,
1
);
// 剪切的宽高比为1:2
17
intent.putExtra(
"outputY"
,
2
);
18
intent.putExtra(
"aspectX"
,
20
);
// 保存图片的宽和高
19
intent.putExtra(
"aspectY"
,
40
);
20
intent.putExtra(
"scale"
,
true
);
21
intent.putExtra(
"noFaceDetection"
,
true
);
22
intent.putExtra(
"output"
, Uri.parse(
"file:///mnt/sdcard/temp"
));
23
startActivityForResult(intent,
0
);
[代码] 打开Google Market
1
// 打开Google Market直接进入该程序的详细页面
2
Uri uri = Uri.parse(
"market://details?id="
+
"com.demo.app"
);
3
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
4
startActivity(intent);
[代码] 安装和卸载程序
1
Uri uri = Uri.fromParts(
"package"
,
"com.demo.app"
,
null
);
2
Intent intent =
new
Intent(Intent.ACTION_DELETE, uri);
3
startActivity(intent);
[代码] 进入设置界面
1
// 进入无线网络设置界面(其它可以举一反三)
2
Intent intent =
new
Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
3
startActivityForResult(intent,
0
);
- Android Intent用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- Android Intent 用法全面总结
- ant android
- uva:111 - History Grading
- 卡尔曾写道,“作为一种技术,书让我们的注意力集中,使我们免受充盈于生活中的分心事所干扰。而一台联网的电脑却做着完全相反的事,它设计出来就是用来分散我们的注意力的……在知道我们的思想深度与专注程度直接相
- Rational Rose 2007 & Rational Rose 2003 下载及破解方法和汉化文件下载
- Linux 音频 驱动 接口 简介 之 OSS 编程 方法 采样频率 量化 位数 实例 driver interface
- Android Intent 用法全面总结
- ant 打包
- Linux音频编程2 音频录放框架
- 第四周实验报告 任务一
- MYSQL引擎
- .Net MVC 分页排序查询综合 - Controller+View
- 选择所有checkbox
- 第四周实验报告 任务三
- 遍历,当前对象为第几个