Android Intent应用,打开网页,安装程序,打电话,打开地图等功能

[java]  view plain copy
  1. 1.从google搜索内容  
  2. Intent intent = new Intent();  
  3. intent.setAction(Intent.ACTION_WEB_SEARCH);  
  4. intent.putExtra(SearchManager.QUERY,"searchString")  
  5. startActivity(intent);  
  6.    
  7. 2.浏览网页  
  8. Uri uri = Uri.parse("http://www.google.com");  
  9. Intent it  = new Intent(Intent.ACTION_VIEW,uri);  
  10. startActivity(it);  
  11.    
  12. 3.显示地图  
  13. Uri uri = Uri.parse("geo:38.899533,-77.036476");  
  14. Intent it = new Intent(Intent.Action_VIEW,uri);  
  15. startActivity(it);  
  16.    
  17. 4.路径规划  
  18. Uri uri = Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat startLng&daddr=endLat endLng&hl=en");  
  19. Intent it = new Intent(Intent.ACTION_VIEW,URI);  
  20. startActivity(it);  
  21.    
  22. 5.拨打电话  
  23. Uri uri = Uri.parse("tel:xxxxxx");  
  24. Intent it = new Intent(Intent.ACTION_DIAL, uri);   
  25. startActivity(it);  
  26.   
  27. 6.调用发短信的程序  
  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.    
  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.   
  48. 8.发送彩信  
  49. Uri uri = Uri.parse("content://media/external/images/media/23");    
  50. Intent it = new Intent(Intent.ACTION_SEND);    
  51. it.putExtra("sms_body""some text");    
  52. it.putExtra(Intent.EXTRA_STREAM, uri);    
  53. it.setType("image/png");    
  54. startActivity(it);  
  55. StringBuilder sb = new StringBuilder();  
  56. sb.append("file://");  
  57. sb.append(fd.getAbsoluteFile());  
  58. Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));  
  59. // Below extra datas are all optional.  
  60. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);  
  61. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);  
  62. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());  
  63. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);  
  64. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);  
  65. startActivity(intent);  
  66.    
  67.   
  68. 9.发送Email  
  69. Uri uri = Uri.parse("mailto:[email protected]");  
  70. Intent it = new Intent(Intent.ACTION_SENDTO, uri);  
  71. startActivity(it);  
  72. Intent it = new Intent(Intent.ACTION_SEND);    
  73. it.putExtra(Intent.EXTRA_EMAIL, "[email protected]");    
  74. it.putExtra(Intent.EXTRA_TEXT, "The email body text");    
  75. it.setType("text/plain");    
  76. startActivity(Intent.createChooser(it, "Choose Email Client"));   
  77. Intent it=new Intent(Intent.ACTION_SEND);      
  78. String[] tos={"[email protected]"};      
  79. String[] ccs={"[email protected]"};      
  80. it.putExtra(Intent.EXTRA_EMAIL, tos);      
  81. it.putExtra(Intent.EXTRA_CC, ccs);      
  82. it.putExtra(Intent.EXTRA_TEXT, "The email body text");      
  83. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");      
  84. it.setType("message/rfc822");      
  85. startActivity(Intent.createChooser(it, "Choose Email Client"));    
  86. Intent it = new Intent(Intent.ACTION_SEND);    
  87. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");    
  88. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");    
  89. sendIntent.setType("audio/mp3");    
  90. startActivity(Intent.createChooser(it, "Choose Email Client"));  
  91.    
  92.    
  93. 10.播放多媒体   
  94. Intent it = new Intent(Intent.ACTION_VIEW);  
  95. Uri uri = Uri.parse("file:///sdcard/song.mp3");  
  96. it.setDataAndType(uri, "audio/mp3");  
  97. startActivity(it);  
  98. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");    
  99. Intent it = new Intent(Intent.ACTION_VIEW, uri);    
  100. startActivity(it);   
  101.    
  102.    
  103. 11.卸载apk  
  104. Uri uri = Uri.fromParts("package", strPackageName, null);    
  105. Intent it = new Intent(Intent.ACTION_DELETE, uri);    
  106. startActivity(it);  
  107.    
  108.    
  109. 12.安装apk  
  110. Uri installUri = Uri.fromParts("package""xxx"null);  
  111. returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);  
  112.    

你可能感兴趣的:(Android Intent应用,打开网页,安装程序,打电话,打开地图等功能)