Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> intent方法使用總結

intent方法使用總結

編輯:初級開發

1. //show webapp: 
2. 
3. Uri uri = Uri.parse("http://www.google.com"); 
4. Intent it = new Intent(Intent.ACTION_VIEW,uri); 
5. startActivity(it); 
6. 
7. //show maps: 
8. Uri uri = Uri.parse("geo:38.899533,-77.036476"); 
9. Intent it = new Intent(Intent.Action_VIEW,uri); 
10. startActivity(it); 
11. 
12. //show ways 
13. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en"); 
14. Intent it = new Intent(Intent.ACTION_VIEW,URI); 
15. startActivity(it); 
16. 
17. //call dial program 
18. Uri uri = Uri.parse("tel:xxxxxx"); 
19. Intent it = new Intent(Intent.ACTION_DIAL, uri); 
20. startActivity(it); 
21. 
22. Uri uri = Uri.parse("tel.xxxxxx"); 
23. Intent it =new Intent(Intent.ACTION_CALL,uri); 
24. //don't forget add this config:<uses-permission id="android.permission.CALL_PHONE" /> 
25. 
26. //send sms/mms 
27. //call sender program 
28. Intent it = new Intent(Intent.ACTION_VIEW); 
29. it.putExtra("sms_body", "The SMS text"); 
30. it.setType("vnd.android-dir/mms-sms"); 
31. startActivity(it); 
32. 
33. //send sms 
34. Uri uri = Uri.parse("smsto:0800000123"); 
35. Intent it = new Intent(Intent.ACTION_SENDTO, uri); 
36. it.putExtra("sms_body", "The SMS text"); 
37. startActivity(it); 
38. 
39. //send mms 
40. Uri uri = Uri.parse("content://media/external/images/media/23"); 
41. Intent it = new Intent(Intent.ACTION_SEND); 
42. it.putExtra("sms_body", "some text"); 
43. it.putExtra(Intent.EXTRA_STREAM, uri); 
44. it.setType("image/png"); 
45. startActivity(it); 
46. 
47. //send email 
48. 
49. Uri uri = Uri.parse("mailto:[email protected]"); 
50. Intent it = new Intent(Intent.ACTION_SENDTO, uri); 
51. startActivity(it); 
52. 
53. Intent it = new Intent(Intent.ACTION_SEND); 
54. it.putExtra(Intent.EXTRA_EMAIL, "[email protected]"); 
55. it.putExtra(Intent.EXTRA_TEXT, "The email body text"); 
56. it.setType("text/plain"); 
57. startActivity(Intent.createChooser(it, "Choose Email ClIEnt")); 
58. 
59. Intent it=new Intent(Intent.ACTION_SEND); 
60. String[] tos={"[email protected]"}; 
61. String[] ccs={"[email protected]"}; 
62. it.putExtra(Intent.EXTRA_EMAIL, tos); 
63. it.putExtra(Intent.EXTRA_CC, ccs); 
64. it.putExtra(Intent.EXTRA_TEXT, "The email body text"); 
65. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 
66. it.setType("message/rfc822"); 
67. startActivity(Intent.createChooser(it, "Choose Email ClIEnt")); 
68. 
69. 
70. //add extra 
71. Intent it = new Intent(Intent.ACTION_SEND); 
72. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 
73. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3"); 
74. sendIntent.setType("audio/mp3"); 
75. startActivity(Intent.createChooser(it, "Choose Email ClIEnt")); 
76. 
77. //play media 
78. Intent it = new Intent(Intent.ACTION_VIEW); 
79. Uri uri = Uri.parse("file:///sdcard/song.mp3"); 
80. it.setDataAndType(uri, "audio/mp3"); 
81. startActivity(it); 
82. 
83. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); 
84. Intent it = new Intent(Intent.ACTION_VIEW, uri); 
85. startActivity(it); 
86. 
87. //Uninstall 
88. Uri uri = Uri.fromParts("package", strPackageName, null); 
89. Intent it = new Intent(Intent.ACTION_DELETE, uri); 
90. startActivity(it); 
91. 
92. //uninstall apk 
93. Uri uninstallUri = Uri.fromParts("package", "xxx", null); 
94. returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri); 
95. 
96. //install apk 
97. Uri installUri = Uri.fromParts("package", "xxx", null); 
98. returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri); 
99. 
100. //play audio 
101. Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3"); 
102. returnIt = new Intent(Intent.ACTION_VIEW, playUri); 
103. 
104. //send extra 
105. Intent it = new Intent(Intent.ACTION_SEND); 
106. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 
107. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3"); 
108. sendIntent.setType("audio/mp3"); 
109. startActivity(Intent.createChooser(it, "Choose Email ClIEnt")); 
110. 
111. //search 
112. Uri uri = Uri.parse("market://search?q=pname:pkg_name"); 
113. Intent it = new Intent(Intent.ACTION_VIEW, uri); 
114. startActivity(it); 
115. //where pkg_name is the full package path for an application 
116. 
117. //show program detail page 
118. Uri uri = Uri.parse("market://details?id=app_id"); 
119. Intent it = new Intent(Intent.ACTION_VIEW, uri); 
120. startActivity(it); 
121. //where app_id is the application ID, find the ID 
122. //by clicking on your application on Market home 
123. //page, and notice the ID from the address bar 
124. 
125. 
126. //search google 
127. Intent intent = new Intent(); 
128. intent.setAction(Intent.ACTION_WEB_SEARCH); 
129. intent.putExtra(SearchManager.QUERY,"searchString") 
130. startActivity(intent);
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved