现在的位置: 首页 > 综合 > 正文

Intent 用法集合

2013年09月09日 ⁄ 综合 ⁄ 共 3747字 ⁄ 字号 评论关闭
  1. //显示网页   
  2. Uri uri = Uri.parse("http://google.com");   
  3. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  4. startActivity(it);     
  5.   
  6. //显示地图   
  7. Uri uri = Uri.parse("geo:38.899533,-77.036476");   
  8. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  9. startActivity(it);   
  10. //其他 geo URI 範例   
  11. //geo:latitude,longitude   
  12. //geo:latitude,longitude?z=zoom   
  13. //geo:0,0?q=my+street+address   
  14. //geo:0,0?q=business+near+city   
  15. //google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom     
  16.   
  17. //路径规划    
  18.   
  19. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat20endLng&hl=en");   
  20. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  21. startActivity(it);   
  22. //where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456      
  23.   
  24. //打电话   
  25. //叫出拨号程序   
  26. Uri uri = Uri.parse("tel:0800000123");   
  27. Intent it = new Intent(Intent.ACTION_DIAL, uri);   
  28. startActivity(it);      
  29.   
  30. //直接打电话出去   
  31. Uri uri = Uri.parse("tel:0800000123");   
  32. Intent it = new Intent(Intent.ACTION_CALL, uri);   
  33. startActivity(it);   
  34. //用這個,要在 AndroidManifest.xml 中,加上   
  35. //<uses-permission id="android.permission.CALL_PHONE" />      
  36.   
  37. //传送SMS/MMS   
  38. //调用短信程序   
  39. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  40. it.putExtra("sms_body""The SMS text");   
  41. it.setType("vnd.android-dir/mms-sms");   
  42. startActivity(it);     
  43.   
  44. //传送消息   
  45. Uri uri = Uri.parse("smsto://0800000123");   
  46. Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
  47. it.putExtra("sms_body""The SMS text");   
  48. startActivity(it);     
  49.   
  50. //传送 MMS   
  51. Uri uri = Uri.parse("content://media/external/images/media/23");   
  52. Intent it = new Intent(Intent.ACTION_SEND);   
  53. it.putExtra("sms_body""some text");   
  54. it.putExtra(Intent.EXTRA_STREAM, uri);   
  55. it.setType("image/png");   
  56. startActivity(it);      
  57.   
  58. //传送 Email   
  59. Uri uri = Uri.parse("mailto:xxx@abc.com");   
  60. Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
  61. startActivity(it);      
  62.   
  63. Intent it = new Intent(Intent.ACTION_SEND);   
  64. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
  65. it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
  66. it.setType("text/plain");   
  67. startActivity(Intent.createChooser(it, "Choose Email Client"));      
  68.   
  69. Intent it=new Intent(Intent.ACTION_SEND);   
  70. String[] tos={"me@abc.com"};   
  71. String[] ccs={"you@abc.com"};   
  72. it.putExtra(Intent.EXTRA_EMAIL, tos);   
  73. it.putExtra(Intent.EXTRA_CC, ccs);   
  74. it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
  75. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
  76. it.setType("message/rfc822");   
  77. startActivity(Intent.createChooser(it, "Choose Email Client"));     
  78.   
  79. //传送附件   
  80. Intent it = new Intent(Intent.ACTION_SEND);   
  81. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
  82. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");   
  83. sendIntent.setType("audio/mp3");   
  84. startActivity(Intent.createChooser(it, "Choose Email Client"));     
  85.   
  86. //播放多媒体   
  87. Uri uri = Uri.parse("file:///sdcard/song.mp3");   
  88. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  89. it.setType("audio/mp3");   
  90. startActivity(it);     
  91.   
  92. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");   
  93. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  94. startActivity(it);     
  95.   
  96. //Market 相关   
  97. //寻找某个应用   
  98. Uri uri = Uri.parse("market://search?q=pname:pkg_name");   
  99. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  100. startActivity(it);   
  101. //where pkg_name is the full package path for an application   
  102. //显示某个应用的相关信息   
  103. Uri uri = Uri.parse("market://details?id=app_id");   
  104. Intent it = new Intent(Intent.ACTION_VIEW, uri);   
  105. startActivity(it);   
  106. //where app_id is the application ID, find the ID   
  107. //by clicking on your application on Market home   
  108. //page, and notice the ID from the address bar     
  109.   
  110. //Uninstall 应用程序   
  111. Uri uri = Uri.fromParts("package", strPackageName, null);   
  112. Intent it = new Intent(Intent.ACTION_DELETE, uri);   
  113. startActivity(it);    
  114. 注:以上可以进行自行验证,笔者正在验证中。。。

抱歉!评论已关闭.