Intent用法实例
来源:互联网 发布:学做菜的软件 编辑:程序博客网 时间:2024/05/19 06:17
1. [代码]调用拨号程序 跳至 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [全屏预览]
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
);
举报
Intent用法大全 1.从google搜索内容
Intent intent = new Intent();intent.setAction(Intent.ACTION_WEB_SEARCH);intent.putExtra(SearchManager.QUERY,"searchString")startActivity(intent);
2.浏览网页
Uri uri = Uri.parse("http://www.google.com");Intent it = new Intent(Intent.ACTION_VIEW,uri);startActivity(it);
3.显示地图
Uri uri = Uri.parse("geo:38.899533,-77.036476");Intent it = new Intent(Intent.Action_VIEW,uri);startActivity(it);
4.路径规划
Uri uri = Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");Intent it = new Intent(Intent.ACTION_VIEW,URI);startActivity(it);
5.拨打电话
Uri uri = Uri.parse("tel:xxxxxx");Intent it = new Intent(Intent.ACTION_DIAL, uri); startActivity(it);
1. //叫出拨号程序 2. Uri uri = Uri.parse("tel:0800000123"); 3. Intent it = new Intent(Intent.ACTION_DIAL, uri); 4. startActivity(it); 1. //直接打电话出去 2. Uri uri = Uri.parse("tel:0800000123"); 3. Intent it = new Intent(Intent.ACTION_CALL, uri); 4. startActivity(it); 5. //用這個,要在 AndroidManifest.xml 中,加上 6. //<uses-permission id="android.permission.CALL_PHONE" />
6.调用发短信的程序
Intent it = new Intent(Intent.ACTION_VIEW); it.putExtra("sms_body", "The SMS text"); it.setType("vnd.android-dir/mms-sms"); startActivity(it);
7.发送短信
Uri uri = Uri.parse("smsto:0800000123"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", "The SMS text"); startActivity(it);
String body="this is sms demo";Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);startActivity(mmsintent);
1. //调用短信程序 2. Intent it = new Intent(Intent.ACTION_VIEW, uri); 3. it.putExtra("sms_body", "The SMS text"); 4. it.setType("vnd.android-dir/mms-sms"); 5. startActivity(it); 1. //传送消息 2. Uri uri = Uri.parse("smsto://0800000123"); 3. Intent it = new Intent(Intent.ACTION_SENDTO, uri); 4. it.putExtra("sms_body", "The SMS text"); 5. startActivity(it); 1. //传送 MMS 2. Uri uri = Uri.parse("content://media/external/images/media/23"); 3. Intent it = new Intent(Intent.ACTION_SEND); 4. it.putExtra("sms_body", "some text"); 5. it.putExtra(Intent.EXTRA_STREAM, uri); 6. it.setType("image/png"); 7. startActivity(it);
8.发送彩信
Uri uri = Uri.parse("content://media/external/images/media/23"); Intent it = new Intent(Intent.ACTION_SEND); it.putExtra("sms_body", "some text"); it.putExtra(Intent.EXTRA_STREAM, uri); it.setType("image/png"); startActivity(it);
StringBuilder sb = new StringBuilder();sb.append("file://");sb.append(fd.getAbsoluteFile());Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));// Below extra datas are all optional.intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);startActivity(intent);
9.发送Email
Uri uri = Uri.parse("mailto:xxx@abc.com");Intent it = new Intent(Intent.ACTION_SENDTO, uri);startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com"); it.putExtra(Intent.EXTRA_TEXT, "The email body text"); it.setType("text/plain"); startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND); String[] tos={"me@abc.com"}; String[] ccs={"you@abc.com"}; it.putExtra(Intent.EXTRA_EMAIL, tos); it.putExtra(Intent.EXTRA_CC, ccs); it.putExtra(Intent.EXTRA_TEXT, "The email body text"); it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); it.setType("message/rfc822"); startActivity(Intent.createChooser(it, "Choose Email Client")); Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3"); sendIntent.setType("audio/mp3"); startActivity(Intent.createChooser(it, "Choose Email Client"));
10.播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);Uri uri = Uri.parse("file:///sdcard/song.mp3");it.setDataAndType(uri, "audio/mp3");startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
11.uninstall apk
Uri uri = Uri.fromParts("package", strPackageName, null); Intent it = new Intent(Intent.ACTION_DELETE, uri); startActivity(it);
12.install apk
Uri installUri = Uri.fromParts("package", "xxx", null);returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
13.两个ActivityIntent it = new Intent(Activity.Main.this, Activity2.class);Bundle bundle=new Bundle();bundle.putString("name", "This is from MainActivity!");it.putExtras(bundle); // it.putExtra(“test”, "shuju”);startActivity(it); // startActivityForResult(it,REQUEST_CODE);
14.发起市场程序Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=pname:org.rabold.android.puzzleblox")); //Uri.parse("market://search?q=pname:org.rabold.android.puzzleblox")); startActivity(intent);
15.调用系统裁剪图片Uri photoUri = Uri.fromFile(new File("/mnt/sdcard/ruhua.jpg"));Log.i("path", photoUri.toString());Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(photoUri, "image/*");intent.putExtra("crop", "true");intent.putExtra("aspectX", 1);intent.putExtra("aspectY", 1);intent.putExtra("outputX", 80);intent.putExtra("outputY", 80);intent.putExtra("output", photoUri);intent.putExtra("outputFormat", "JPEG");
16.获取图片Intent intent = new Intent();/* 设置为image */intent.setType("image/*");/* 使用Intent.ACTION_GET_CONTENT这个Action */intent.setAction(Intent.ACTION_GET_CONTENT);/* 取得图片后返回本画面 */startActivityForResult(intent, 1);
17.实现分享功能 Intent mIntent = new Intent(Intent.ACTION_SEND);//根据分享的内容设置不同的mimeTypemIntent.setType("text/plain");mIntent.putExtra(Intent.EXTRA_TEXT, "下载地址?");mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(Intent.createChooser(mIntent, "分享"));
18.返回桌面 Intent unMyIntent = new Intent(Intent.ACTION_MAIN); unMyIntent.addCategory(Intent.CATEGORY_HOME); startActivity(unMyIntent);
19.发起一个应用程序 ComponentName 两个参数一个是包名 一个是包下的主类 final Intent intent = new Intent(Intent.ACTION_MAIN, null);intent.addCategory(Intent.CATEGORY_LAUNCHER);final ComponentName cn = new ComponentName("com.android.settings","com.android.settings.fuelgauge.PowerUsageSummary");intent.setComponent(cn);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity( intent);
0 0
- Intent用法实例
- 一些Intent用法实例
- Intent用法实例
- Intent用法实例
- Intent 用法具体实例
- 一些Intent用法实例
- Intent的实例用法
- Android:intent用法实例
- Intent用法实例
- intent 用法 实例
- Intent用法实例
- Intent用法实例
- Intent用法实例
- Intent用法实例
- Intent用法实例
- Intent用法实例
- android的Intent用法实例
- android的Intent用法实例
- 电商全渠道秩序维护 八爪鱼大数据来帮忙
- XML 查询、添加、修改、删除
- oracle exp-00011的解决办法
- 职场“狡兔死走狗烹”的破解之道
- linux命令后台运行
- Intent用法实例
- android内存泄露分析-MAT
- rc4加密算法
- Sencha Architect toolbar Button右对齐
- KMP算法详解(转)
- Reporting Services 学习教程地址
- 找规律
- linux下的mount挂载命令
- 次方求模