Android Intent调用

android技术开发 发布于 2013/08/22 14:42
阅读 161
收藏 6

Android Intent调用

今天我们就来说说Intent是怎么样调用的,下面的代码写的很全,大家可以来看看。

Java代码:

1 //调用浏览器 

2 Uriuri=Uri.parse(""); 

3 Intentit=newIntent(Intent.ACTION_VIEW,uri); 

4 startActivity(it); 

5 //显示某个坐标在地图上 

6 Uriuri=Uri.parse("geo:38.899533,-77.036476"); 

7 Intentit=newIntent(Intent.Action_VIEW,uri); 

8 startActivity(it); 


9 //显示路径 

10 Uriuri=Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en"); 

11 Intentit=newIntent(Intent.ACTION_VIEW,URI); 

12 startActivity(it); 


13 //拨打电话 

14 Uriuri=Uri.parse("tel:10086"); 

15 Intentit=newIntent(Intent.ACTION_DIAL,uri);

16 startActivity(it); 

17 Uriuri=Uri.parse("tel.10086"); 

18 Intentit=newIntent(Intent.ACTION_CALL,uri); 

19 需要添加<uses-permissionid="android.permission.CALL_PHONE"/>这个权限到androidmanifest.xml 

20 

21 //发送短信或彩信 

22 Intentit=newIntent(Intent.ACTION_VIEW); 

23 it.putExtra("sms_body","TheSMStext"); 

24 it.setType("vnd.android-dir/mms-sms"); 

25 startActivity(it); 

26 

27 //发送短信 

28 Uriuri=Uri.parse("smsto:10086"); 

29 Intentit=newIntent(Intent.ACTION_SENDTO,uri); 

30 it.putExtra("sms_body","cwj"); 

31 startActivity(it); 



32 //发送彩信 

33 Uriuri=Uri.parse("content://media/external/images/media/23"); 

34 Intentit=newIntent(Intent.ACTION_SEND); 

35 it.putExtra("sms_body","sometext"); 

36 it.putExtra(Intent.EXTRA_STREAM,uri); 

37 it.setType("image/png"); 

38 startActivity(it); 


39 //发送邮件 

40 Uriuri=Uri.parse("mailto:android123@163.com"); 

41 Intentit=newIntent(Intent.ACTION_SENDTO,uri); 

42 startActivity(it); 

43 Intentit=newIntent(Intent.ACTION_SEND); 

44 it.putExtra(Intent.EXTRA_EMAIL,android123@163.com); 

45 it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext"); 

46 it.setType("text/plain"); 

47 startActivity(Intent.createChooser(it,"ChooseEmailClient")); 

48 Intentit=newIntent(Intent.ACTION_SEND); 

49 String[]tos={"me@abc.com"};

50 String[]ccs={"you@abc.com"}; 

51 it.putExtra(Intent.EXTRA_EMAIL,tos); 

52 it.putExtra(Intent.EXTRA_CC,ccs); 

53 it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext"); 

54 it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext"); 

55 it.setType("message/rfc822"); 

56 startActivity(Intent.createChooser(it,"ChooseEmailClient")); 


57 //播放媒体文件 

58 Intentit=newIntent(Intent.ACTION_VIEW); 

59 Uriuri=Uri.parse("file:///sdcard/cwj.mp3"); 

60 it.setDataAndType(uri,"audio/mp3"); 

61 startActivity(it); 

62 Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1"); 

63 Intentit=newIntent(Intent.ACTION_VIEW,uri); 

64 startActivity(it); 


65 //卸载APK 

66 Uriuri=Uri.fromParts("package",strPackageName,null); 

67 Intentit=newIntent(Intent.ACTION_DELETE,uri); 

68 startActivity(it); 


69 //卸载apk2 

70 UriuninstallUri=Uri.fromParts("package","xxx",null); 

71 returnIt=newIntent(Intent.ACTION_DELETE,uninstallUri); 


72 //安装APK 

73 UriinstallUri=Uri.fromParts("package","xxx",null); 

74 returnIt=newIntent(Intent.ACTION_PACKAGE_ADDED,installUri); 


75 //播放音乐 

76 UriplayUri=Uri.parse("file:///sdcard/download/sth.mp3"); 

77 returnIt=newIntent(Intent.ACTION_VIEW,playUri);

78 

79 //发送附近 

80 Intentit=newIntent(Intent.ACTION_SEND); 

81 it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext"); 

82 it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/cwj.mp3"); 

83 sendIntent.setType("audio/mp3"); 

84 startActivity(Intent.createChooser(it,"ChooseEmailClient")); 

85 //market上某个应用信,pkg_name就是应用的packageName 

86 Uriuri=Uri.parse("market://search?q=pname:pkg_name"); 

87 Intentit=newIntent(Intent.ACTION_VIEW,uri); 

88 startActivity(it); 

89 //market上某个应用信息,app_id可以通过www网站看下 

90 Uriuri=Uri.parse("market://details?id=app_id"); 

91 Intentit=newIntent(Intent.ACTION_VIEW,uri); 

92 startActivity(it); 

93 

94 //调用搜索 

95 Intentintent=newIntent(); 

96 intent.setAction(Intent.ACTION_WEB_SEARCH); 

97 intent.putExtra(SearchManager.QUERY,"android123") 

98 startActivity(intent); 

交流群:164427941



加载中
返回顶部
顶部