android intent和intent action大全

来源:互联网 发布:淘宝回收手机在哪 编辑:程序博客网 时间:2024/06/05 03:16
  1. android 中intent是经常要用到的。不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到intent。在做了一些intent的例子之后,整理了一下intent,希望对大家有用。由于intent内容太多,不可能真的写全,难免会有遗落,以后我会随时更新。如果你们有疑问或新的intent内容,希望交流。   
  2. ★intent大全:   
  3. 1.从google搜索内容   
  4. Intent intent = new Intent();   
  5. intent.setAction(Intent.ACTION_WEB_SEARCH);   
  6. intent.putExtra(SearchManager.QUERY,"searchString")   
  7. startActivity(intent);   
  8.   
  9. 2.浏览网页   
  10. Uri uri = Uri.parse("http://www.google.com");   
  11. Intent it   = new Intent(Intent.ACTION_VIEW,uri);   
  12. startActivity(it);   
  13.   
  14. 3.显示地图   
  15. Uri uri = Uri.parse("geo:38.899533,-77.036476");   
  16. Intent it = new Intent(Intent.Action_VIEW,uri);   
  17. startActivity(it);   
  18.   
  19. 4.路径规划   
  20. Uri uri = Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");   
  21. Intent it = new Intent(Intent.ACTION_VIEW,URI);   
  22. startActivity(it);   
  23.   
  24. 5.拨打电话   
  25. Uri uri = Uri.parse("tel:xxxxxx");   
  26. Intent it = new Intent(Intent.ACTION_DIAL, uri);     
  27. startActivity(it);   
  28.   
  29. 6.调用发短信的程序   
  30. Intent it = new Intent(Intent.ACTION_VIEW);     
  31. it.putExtra("sms_body""The SMS text");     
  32. it.setType("vnd.android-dir/mms-sms");     
  33. startActivity(it);   
  34.   
  35. 7.发送短信   
  36. Uri uri = Uri.parse("smsto:0800000123");     
  37. Intent it = new Intent(Intent.ACTION_SENDTO, uri);     
  38. it.putExtra("sms_body""The SMS text");     
  39. startActivity(it);   
  40. String body="this is sms demo";   
  41. Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));   
  42. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);   
  43. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);   
  44. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);   
  45. startActivity(mmsintent);   
  46.   
  47. 8.发送彩信   
  48. Uri uri = Uri.parse("content://media/external/images/media/23");     
  49. Intent it = new Intent(Intent.ACTION_SEND);     
  50. it.putExtra("sms_body""some text");     
  51. it.putExtra(Intent.EXTRA_STREAM, uri);     
  52. it.setType("image/png");     
  53. startActivity(it);   
  54. StringBuilder sb = new StringBuilder();   
  55. sb.append("file://");   
  56. sb.append(fd.getAbsoluteFile());   
  57. Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));   
  58. // Below extra datas are all optional.   
  59. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);   
  60. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);   
  61. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());   
  62. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);   
  63. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);   
  64. startActivity(intent);   
  65.   
  66. 9.发送Email   
  67. Uri uri = Uri.parse("mailto:xxx@abc.com");   
  68. Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
  69. startActivity(it);   
  70. Intent it = new Intent(Intent.ACTION_SEND);     
  71. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");     
  72. it.putExtra(Intent.EXTRA_TEXT, "The email body text");     
  73. it.setType("text/plain");     
  74. startActivity(Intent.createChooser(it, "Choose Email Client"));   
  75. Intent it=new Intent(Intent.ACTION_SEND);       
  76. String[] tos={"me@abc.com"};       
  77. String[] ccs={"you@abc.com"};       
  78. it.putExtra(Intent.EXTRA_EMAIL, tos);       
  79. it.putExtra(Intent.EXTRA_CC, ccs);       
  80. it.putExtra(Intent.EXTRA_TEXT, "The email body text");       
  81. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");       
  82. it.setType("message/rfc822");       
  83. startActivity(Intent.createChooser(it, "Choose Email Client"));     
  84.   
  85. Intent it = new Intent(Intent.ACTION_SEND);     
  86. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");     
  87. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");     
  88. sendIntent.setType("audio/mp3");     
  89. startActivity(Intent.createChooser(it, "Choose Email Client"));   
  90.   
  91. 10.播放多媒体     
  92. Intent it = new Intent(Intent.ACTION_VIEW);   
  93. Uri uri = Uri.parse("file:///sdcard/song.mp3");   
  94. it.setDataAndType(uri, "audio/mp3");   
  95. startActivity(it);   
  96. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");     
  97. Intent it = new Intent(Intent.ACTION_VIEW, uri);     
  98. startActivity(it);   
  99.   
  100. 11.uninstall apk   
  101. Uri uri = Uri.fromParts("package", strPackageName, null);     
  102. Intent it = new Intent(Intent.ACTION_DELETE, uri);     
  103. startActivity(it);   
  104.   
  105. 12.install apk   
  106. Uri installUri = Uri.fromParts("package""xxx"null);   
  107. returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);   
  108.   
  109. 13. 打开照相机   
  110. <1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);   
  111.           this.sendBroadcast(i);   
  112.     <2>long dateTaken = System.currentTimeMillis();   
  113.          String name = createName(dateTaken) + ".jpg";   
  114.          fileName = folder + name;   
  115.          ContentValues values = new ContentValues();   
  116.          values.put(Images.Media.TITLE, fileName);   
  117.          values.put("_data", fileName);   
  118.          values.put(Images.Media.PICASA_ID, fileName);   
  119.          values.put(Images.Media.DISPLAY_NAME, fileName);   
  120.          values.put(Images.Media.DESCRIPTION, fileName);   
  121.          values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);   
  122.          Uri photoUri = getContentResolver().insert(   
  123.                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);   
  124.              
  125.          Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
  126.          inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);   
  127.          startActivityForResult(inttPhoto, 10);   
  128.   
  129. 14.从gallery选取图片   
  130.    Intent i = new Intent();   
  131.          i.setType("image/*");   
  132.          i.setAction(Intent.ACTION_GET_CONTENT);   
  133.          startActivityForResult(i, 11);   
  134.   
  135. 15. 打开录音机   
  136. Intent mi = new Intent(Media.RECORD_SOUND_ACTION);   
  137.          startActivity(mi);   
  138.   
  139. 16.显示应用详细列表        
  140. Uri uri = Uri.parse("market://details?id=app_id");          
  141. Intent it = new Intent(Intent.ACTION_VIEW, uri);          
  142. startActivity(it);          
  143. //where app_id is the application ID, find the ID           
  144. //by clicking on your application on Market home           
  145. //page, and notice the ID from the address bar       
  146.   
  147. 刚才找app id未果,结果发现用package name也可以   
  148. Uri uri = Uri.parse("market://details?id=<packagename>");   
  149. 这个简单多了   
  150.   
  151. 17寻找应用        
  152. Uri uri = Uri.parse("market://search?q=pname:pkg_name");          
  153. Intent it = new Intent(Intent.ACTION_VIEW, uri);          
  154. startActivity(it);   
  155. //where pkg_name is the full package path for an application        
  156.   
  157. 18打开联系人列表   
  158.          <1>             
  159.           Intent i = new Intent();   
  160.           i.setAction(Intent.ACTION_GET_CONTENT);   
  161.           i.setType("vnd.android.cursor.item/phone");   
  162.           startActivityForResult(i, REQUEST_TEXT);   
  163.   
  164.          <2>   
  165.          Uri uri = Uri.parse("content://contacts/people");   
  166.          Intent it = new Intent(Intent.ACTION_PICK, uri);   
  167.          startActivityForResult(it, REQUEST_TEXT);   
  168.   
  169. 19 打开另一程序   
  170. Intent i = new Intent();   
  171.          ComponentName cn = new ComponentName("com.yellowbook.android2",   
  172.                    "com.yellowbook.android2.AndroidSearch");   
  173.          i.setComponent(cn);   
  174.          i.setAction("android.intent.action.MAIN");   
  175.          startActivityForResult(i, RESULT_OK);   
  176.   
  177. ★intent action大全:   
  178. android.intent.action.ALL_APPS  
  179. android.intent.action.ANSWER  
  180. android.intent.action.ATTACH_DATA  
  181. android.intent.action.BUG_REPORT  
  182. android.intent.action.CALL  
  183. android.intent.action.CALL_BUTTON  
  184. android.intent.action.CHOOSER  
  185. android.intent.action.CREATE_LIVE_FOLDER  
  186. android.intent.action.CREATE_SHORTCUT  
  187. android.intent.action.DELETE  
  188. android.intent.action.DIAL  
  189. android.intent.action.EDIT  
  190. android.intent.action.GET_CONTENT  
  191. android.intent.action.INSERT  
  192. android.intent.action.INSERT_OR_EDIT  
  193. android.intent.action.MAIN  
  194. android.intent.action.MEDIA_SEARCH  
  195. android.intent.action.PICK  
  196. android.intent.action.PICK_ACTIVITY  
  197. android.intent.action.RINGTONE_PICKER  
  198. android.intent.action.RUN  
  199. android.intent.action.SEARCH  
  200. android.intent.action.SEARCH_LONG_PRESS  
  201. android.intent.action.SEND  
  202. android.intent.action.SENDTO  
  203. android.intent.action.SET_WALLPAPER  
  204. android.intent.action.SYNC  
  205. android.intent.action.SYSTEM_TUTORIAL  
  206. android.intent.action.VIEW  
  207. android.intent.action.VOICE_COMMAND  
  208. android.intent.action.WEB_SEARCH  
  209. android.net.wifi.PICK_WIFI_NETWORK  
  210. android.settings.AIRPLANE_MODE_SETTINGS  
  211. android.settings.APN_SETTINGS  
  212. android.settings.APPLICATION_DEVELOPMENT_SETTINGS  
  213. android.settings.APPLICATION_SETTINGS  
  214. android.settings.BLUETOOTH_SETTINGS  
  215. android.settings.DATA_ROAMING_SETTINGS  
  216. android.settings.DATE_SETTINGS  
  217. android.settings.DISPLAY_SETTINGS  
  218. android.settings.INPUT_METHOD_SETTINGS  
  219. android.settings.INTERNAL_STORAGE_SETTINGS  
  220. android.settings.LOCALE_SETTINGS  
  221. android.settings.LOCATION_SOURCE_SETTINGS  
  222. android.settings.MANAGE_APPLICATIONS_SETTINGS  
  223. android.settings.MEMORY_CARD_SETTINGS  
  224. android.settings.NETWORK_OPERATOR_SETTINGS  
  225. android.settings.QUICK_LAUNCH_SETTINGS  
  226. android.settings.SECURITY_SETTINGS  
  227. android.settings.SETTINGS  
  228. android.settings.SOUND_SETTINGS  
  229. android.settings.SYNC_SETTINGS  
  230. android.settings.USER_DICTIONARY_SETTINGS  
  231. android.settings.WIFI_IP_SETTINGS  
  232. android.settings.WIFI_SETTINGS  
  233. android.settings.WIRELESS_SETTINGS  

转载自:http://a38876399.iteye.com/blog/800133
原创粉丝点击