[代码] [Java]代码
01
//以下是常用到的Intent的URI及其示例,包含了大部分应用中用到的共用Intent。
02
//一、打开一个网页,类别是Intent.ACTION_VIEW
03
Uri uri = Uri.parse( http://blog.3gstdy.com/ );
04
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
05
//二、打开地图并定位到一个点
06
Uri uri = Uri.parse( geo:52.76,-79.0342 );
07
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
08
//三、打开拨号界面 ,类型是Intent.ACTION_DIAL
09
Uri uri = Uri.parse( tel:10086 );
10
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
11
//四、直接拨打电话,与三不同的是,这个直接拨打电话,而不是打开拨号界面
12
Uri uri = Uri.parse( tel:10086 );
13
Intent intent = new Intent(Intent.ACTION_CALL, uri);
14
//五、卸载一个应用,Intent的类别是Intent.ACTION_DELETE
15
Uri uri = Uri.fromParts( package ,xxx , null);
16
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
17
//六、安装应用程序,Intent的类别是Intent.ACTION_PACKAGE_ADDED
18
Uri uri = Uri.fromParts( package ,xxx , null);
19
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);
20
//七、播放音频文件
21
Uri uri = Uri.parse( file:///sdcard/download/everything.mp3 );
22
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
23
intent.setType( audio/mp3 );
24
//八、打开发邮件界面
25
Uri uri= Uri.parse( mailto:admin@3gstdy.com );
26
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
27
//九、发邮件,与八不同这里是将邮件发送出去,
28
Intent intent = new Intent(Intent.ACTION_SEND);
29
String[] tos = {admin@3gstdy.com};
30
String[] ccs = {webmaster@3gstdy.com};
31
intent.putExtra(Intent.EXTRA_EMAIL, tos);
32
intent.putExtra(Intent.EXTRA_CC, ccs);
33
intent.putExtra(Intent.EXTRA_TEXT,I come from http://blog.3gstdy.com );
34
intent.putExtra(Intent.EXTRA_SUBJECT,http://blog.3gstdy.com );intent.setType( message/rfc882 );
35
Intent.createChooser(intent,Choose Email Client );
36
//发送带附件的邮件
37
Intent intent = new Intent(Intent.ACTION_SEND);
38
intent.putExtra(Intent.EXTRA_SUBJECT,The email subject text );
39
intent.putExtra(Intent.EXTRA_STREAM,file:///sdcard/mysong.mp3 );
40
intent.setType( audio/mp3 );
41
startActivity(Intent.createChooser(intent,Choose Email Client ));
42
//十、发短信
43
Uri uri= Uri.parse( tel:10086 );
44
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
45
intent.putExtra( sms_body ,I come from http://blog.3gstdy.com );
46
intent.setType( vnd.Android-dir/mms-sms );
47
//十一、直接发邮件
48
Uri uri= Uri.parse( smsto://100861 );
49
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
50
intent.putExtra( sms_body ,3g android http://blog.3gstdy.com );
51
//十二、发彩信
52
Uri uri= Uri.parse( content://media/external/images/media/23 );
53
Intent intent = new Intent(Intent.ACTION_SEND);
54
intent.putExtra( sms_body ,3g android http://blog.3gstdy.com );
55
intent.putExtra(Intent.EXTRA_STREAM, uri);
56
intent.setType( image/png );
57
//十三、# Market 相关
58
//1 //寻找某个应用
59
Uri uri = Uri.parse( market://search?q=pname:pkg_name );
60
Intent it = new Intent(Intent.ACTION_VIEW, uri);
61
startActivity(it);
62
//where pkg_name is the full package path for an application
63
//2 //显示某个应用的相关信息
64
Uri uri = Uri.parse( market://details?id=app_id );
65
Intent it = new Intent(Intent.ACTION_VIEW, uri);
66
startActivity(it);
67
//where app_id is the application ID, find the ID
68
//by clicking on your application on Market home
69
//page, and notice the ID from the address bar
70
//十四、路径规划
71
Uri uri = Uri.parse( http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en );
72
Intent it = new Intent(Intent.ACTION_VIEW, uri);
73
startActivity(it);