下面列出几种Intent的用法
显示网页:
1 Uri uri = Uri.parse("http://www.google.com");
2 Intent it = new Intent(Intent.ACTION_VIEW,uri);
3 startActivity(it);
显示地图:
4 Uri uri = Uri.parse("geo:38.899533,-77.036476");
5 Intent it = new Intent(Intent.Action_VIEW,uri);
6 startActivity(it);
路径规划:
7 Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
8 Intent it = new Intent(Intent.ACTION_VIEW,URI);
9 startActivity(it);
拨打电话:
调用拨号程序
10 Uri uri = Uri.parse("tel:xxxxxx");
11 Intent it = new Intent(Intent.ACTION_DIAL, uri);
12 startActivity(it);
13 Uri uri = Uri.parse("tel.xxxxxx");
14 Intent it =new Intent(Intent.ACTION_CALL,uri);
15 要使用这个必须在配置文件中加入<uses-permission id="android .permission.CALL_PHONE" />
发送SMS/MMS
调用发送短信
的程序
16 Intent it = new Intent(Intent.ACTION_VIEW);
17 it.putExtra("sms_body", "The SMS text");
18 it.setType("vnd.android-dir/mms-sms");
19 startActivity(it);
发送短信
20 Uri uri = Uri.parse("smsto:0800000123");
21 Intent it = new Intent(Intent.ACTION_SENDTO, uri);
22 it.putExtra("sms_body", "The SMS text");
23 startActivity(it);
发送彩信
24 Uri uri = Uri.parse("content://media/external/images/media/23");
25 Intent it = new Intent(Intent.ACTION_SEND);
26 it.putExtra("sms_body", "some text");
27 it.putExtra(Intent.EXTRA_STREAM, uri);
28 it.setType("image/png");
29 startActivity(it);
发送Email
30
31 Uri uri = Uri.parse("mailto:xxx@abc.com");
32 Intent it = new Intent(Intent.ACTION_SENDTO, uri);
33 startActivity(it);
34 Intent it = new Intent(Intent.ACTION_SEND);
35 it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
36 it.putExtra(Intent.EXTRA_TEXT, "The email body text");
37 it.setType("text/plain");
38 startActivity(Intent.createChooser(it, "Choose Email Client"));
39 Intent it=new Intent(Intent.ACTION_SEND);
40 String[] tos={"me@abc.com"};
41 String[] ccs={"you@abc.com"};
42 it.putExtra(Intent.EXTRA_EMAIL, tos);
43 it.putExtra(Intent.EXTRA_CC, ccs);
44 it.putExtra(Intent.EXTRA_TEXT, "The email body text");
45 it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
46 it.setType("message/rfc822");
47 startActivity(Intent.createChooser(it, "Choose Email Client"));
添加附件
48 Intent it = new Intent(Intent.ACTION_SEND);
49 it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
50 it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
51 sendIntent.setType("audio/mp3");
52 startActivity(Intent.createChooser(it, "Choose Email Client"));
53 //发送附件
54 Intent it = new Intent(Intent.ACTION_SEND);
55 it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
56 it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");
57 sendIntent.setType("audio/mp3");
58 startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
59
60 Intent it = new Intent(Intent.ACTION_VIEW);
61 Uri uri = Uri.parse("file:///sdcard/song.mp3");
62 it.setDataAndType(uri, "audio/mp3");
63 startActivity(it);
64 Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
65 Intent it = new Intent(Intent.ACTION_VIEW, uri);
66 startActivity(it);
Uninstall 程序
67 Uri uri = Uri.fromParts("package", strPackageName, null);
68 Intent it = new Intent(Intent.ACTION_DELETE, uri);
69 startActivity(it);
uninstall apk
70 Uri uninstallUri = Uri.fromParts("package", "xxx", null);
71
72 returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);
install apk
73 Intent intent = new Intent(Intent.ACTION_VIEW);
74 intent.setDataAndType(Uri.parse("file:///sdcard/test.apk"), "application/vnd.android.package-archive");
75
76 startActivity(intent);
play audio
77 Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
78
79 returnIt = new Intent(Intent.ACTION_VIEW, playUri);
80 //搜索应用
81 Uri uri = Uri.parse("market://search?q=pname:pkg_name");
82 Intent it = new Intent(Intent.ACTION_VIEW, uri);
83 startActivity(it);
84 //where pkg_name is the full package path for an application
85
86 //显示指定应用的详细页面(这个好像不支持了,找不到app_id)
87 Uri uri = Uri.parse("market://details?id=app_id");
88 Intent it = new Intent(Intent.ACTION_VIEW, uri);
89 startActivity(it);
90 //where app_id is the application ID, find the ID
91 //by clicking on your application on Market home
92 //page, and notice the ID from the address bar