android 中intent是经常要用到的。不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到intent。在做了一些intent的例子之后,整理了一下intent,希望对大家有用。由于intent内容太多,不可能真的写全,难免会有遗落,以后我会随时更新。如果你们有疑问或新的intent内容,希望交流。

下面是启动系统的Intent:

1.从google搜索内容

 
   
  1. Intent intent = new Intent();   
  2.  
  3. intent.setAction(Intent.ACTION_WEB_SEARCH);  
  4.  
  5. intent.putExtra(SearchManager.QUERY,"searchString")  
  6.  
  7. startActivity(intent);   
  8.  

 2.浏览网页

 
   
  1. Uri uri =Uri.parse("http://www.google.com");   
  2.  
  3. Intent it = new Intent(Intent.ACTION_VIEW,uri);   
  4.  
  5. startActivity(it);   

3.显示地图

 
   
  1. Uri uri = Uri.parse("geo:38.899533,-77.036476");  
  2.  
  3. Intent it = newIntent(Intent.Action_VIEW,uri);   
  4.  
  5. startActivity(it);  

4.路径规划

 
   
  1. Uri uri =Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");  
  2.  
  3. Intent it = newIntent(Intent.ACTION_VIEW,URI);   
  4.  
  5. startActivity(it);   

5.拨打电话

 
   
  1. Uri uri =Uri.parse("tel:xxxxxx");   
  2.  
  3. Intent it = new Intent(Intent.ACTION_DIAL,uri);     
  4.  
  5. startActivity(it); 

6.调用发短信的程序

 
   
  1. Intent it = newIntent(Intent.ACTION_VIEW);      
  2.  
  3. it.putExtra("sms_body""TheSMS text");      
  4.  
  5. it.setType("vnd.android-dir/mms-sms");      
  6.  
  7. startActivity(it);  

7.发送短信

 
   
  1. Uri uri =Uri.parse("smsto:0800000123");     
  2.  
  3. Intent it = newIntent(Intent.ACTION_SENDTO, uri);      
  4.  
  5. it.putExtra("sms_body""TheSMS text");      
  6.  
  7. startActivity(it);   
  8.  
  9. String body="this is sms demo";   
  10.  
  11. Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));   
  12.  
  13. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);   
  14.  
  15. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);   
  16.  
  17. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);   
  18.  
  19. startActivity(mmsintent);  

8.发送彩信

 
   
  1. Uri uri =Uri.parse("content://media/external/p_w_picpaths/media/23");      
  2.  
  3. Intent it = newIntent(Intent.ACTION_SEND);      
  4.  
  5. it.putExtra("sms_body","some text");      
  6.  
  7. it.putExtra(Intent.EXTRA_STREAM, uri);      
  8.  
  9. it.setType("p_w_picpath/png");      
  10.  
  11. startActivity(it);   
  12.  
  13. StringBuilder sb = new StringBuilder();   
  14.  
  15. sb.append("file://");   
  16.  
  17. sb.append(fd.getAbsoluteFile());   
  18.  
  19. Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));   
  20.  
  21. // Below extra datas are all optional.   
  22.  
  23. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);   
  24.  
  25. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);   
  26.  
  27. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());   
  28.  
  29. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);   
  30.  
  31. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);   
  32.  
  33. startActivity(intent);  

9.发送Email

 
   
  1. Uri uri =Uri.parse("mailto:xxx@abc.com");   
  2.  
  3. Intent it = newIntent(Intent.ACTION_SENDTO, uri);   
  4.  
  5. startActivity(it);   
  6.  
  7. Intent it = new Intent(Intent.ACTION_SEND);      
  8.  
  9. it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");      
  10.  
  11. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");      
  12.  
  13. it.setType("text/plain");      
  14.  
  15. startActivity(Intent.createChooser(it,"Choose Email Client"));   
  16.  
  17. Intent it=new Intent(Intent.ACTION_SEND);        
  18.  
  19. String[] tos={"me@abc.com"};        
  20.  
  21. String[]ccs={"you@abc.com"};        
  22.  
  23. it.putExtra(Intent.EXTRA_EMAIL, tos);        
  24.  
  25. it.putExtra(Intent.EXTRA_CC, ccs);        
  26.  
  27. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");        
  28.  
  29. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");        
  30.  
  31. it.setType("message/rfc822");        
  32.  
  33. startActivity(Intent.createChooser(it,"Choose Email Client"));      
  34.  
  35.    
  36.  
  37. Intent it = newIntent(Intent.ACTION_SEND);      
  38.  
  39. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");      
  40.  
  41. it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");     
  42.  
  43. sendIntent.setType("audio/mp3");      
  44.  
  45. startActivity(Intent.createChooser(it,"Choose Email Client"));   
 

10.播放多媒体  

 
   
  1. Intent it = new Intent(Intent.ACTION_VIEW);  
  2.  
  3. Uri uri =Uri.parse("file:///sdcard/song.mp3");   
  4.  
  5. it.setDataAndType(uri,"audio/mp3");   
  6.  
  7. startActivity(it);   
  8.  
  9. Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");      
  10.  
  11. Intent it = new Intent(Intent.ACTION_VIEW,uri);      
  12.  
  13. startActivity(it);  

11.uninstall apk

 
   
  1. Uri uri =Uri.fromParts("package", strPackageName, null);      
  2.  
  3. Intent it = newIntent(Intent.ACTION_DELETE, uri);      
  4.  
  5. startActivity(it);  

12.install apk

 
   
  1. Uri installUri = Uri.fromParts("package","xxx"null);   
  2.  
  3. returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri); 

13. 打开照相机

   <1>

 
   
  1. Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);   
  2. this.sendBroadcast(i);   
  3.  

    <2>

 
   
  1. long dateTaken = System.currentTimeMillis();   
  2.  
  3. String name = createName(dateTaken) + ".jpg";   
  4.  
  5. fileName = folder + name;   
  6.  
  7. ContentValues values = new ContentValues();   
  8.  
  9. values.put(Images.Media.TITLE, fileName);   
  10.  
  11. values.put("_data", fileName);   
  12.  
  13. values.put(Images.Media.PICASA_ID, fileName);   
  14.  
  15. values.put(Images.Media.DISPLAY_NAME, fileName);   
  16.  
  17. values.put(Images.Media.DESCRIPTION, fileName);   
  18.  
  19. values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);   
  20.  
  21. Uri photoUri = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);   
  22.  
  23. Intent inttPhoto = new Intent MediaStore.ACTION_IMAGE_CAPTURE);   
  24.  
  25. inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);   
  26.  
  27. startActivityForResult(inttPhoto, 10);   

 14.从gallery选取图片 

 
   
  1. Intent i = new Intent();   
  2.  
  3. i.setType("p_w_picpath/*");   
  4.  
  5. i.setAction(Intent.ACTION_GET_CONTENT);   
  6.  
  7. startActivityForResult(i, 11);   
  8.  

15. 打开录音机

 
   
  1. Intent mi = new Intent(Media.RECORD_SOUND_ACTION);   
  2.  
  3. startActivity(mi);   
  4.  

16.显示应用详细列表      

 
   
  1. Uri uri =Uri.parse("market://details?id=app_id");           
  2.  
  3. Intent it = new Intent(Intent.ACTION_VIEW,uri);           
  4.  
  5. startActivity(it);           
  6.  
  7. //where app_id is the application ID, findthe ID            
  8.  
  9. //by clicking on your application on Markethome            
  10.  
  11. //page, and notice the ID from the addressbar       
  

刚才找app id未果,结果发现用package name也可以,这个简单多了

 
   
  1. Uri uri =Uri.parse("market://details?id=<packagename>");  

17.寻找应用      

 
   
  1. Uri uri =Uri.parse("market://search?q=pname:pkg_name");           
  2.  
  3. Intent it = new Intent(Intent.ACTION_VIEW,uri);           
  4.  
  5. startActivity(it);   
  6.  
  7. //where pkg_name is the full package pathfor an application         
  8.  
 

18.打开联系人列表

         <1>           

 
   
  1. Intent i = new Intent();   
  2.  
  3. i.setAction(Intent.ACTION_GET_CONTENT);   
  4.  
  5. i.setType("vnd.android.cursor.item/phone");   
  6.  
  7. startActivityForResult(i, REQUEST_TEXT);   
  8.  

           <2>

 
   
  1. Uri uri = Uri.parse("content://contacts/people");   
  2.  
  3. Intent it = new Intent(Intent.ACTION_PICK, uri);   
  4.  
  5. startActivityForResult(it, REQUEST_TEXT);   
  6.  
  7.    
  8.  

19 打开另一程序

 
   
  1. Intent i = new Intent();   
  2.  
  3. ComponentName cn = newComponentName("com.yellowbook.android2",   
  4.  
  5. "com.yellowbook.android2.AndroidSearch");   
  6.  
  7. i.setComponent(cn);   
  8.  
  9. i.setAction("android.intent.action.MAIN");   
  10.  
  11. startActivityForResult(i, RESULT_OK);   
 

20.调用系统编辑添加联系人(高版本SDK有效):

 
   
  1. Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);   
  2.  
  3. it.setType("vnd.android.cursor.item/contact");   
  4.  
  5. //it.setType(Contacts.CONTENT_ITEM_TYPE);   
  6.  
  7. it.putExtra("name","myName");   
  8.  
  9. it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,  "organization");   
  10.  
  11. it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");   
  12. it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");  
  13.  
  14. it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE, "mobilePhone");   
  15.  
  16. it.putExtra(  android.provider.Contacts.Intents.Insert.TERTIARY_PHONE, "workPhone");   
  17.  
  18. it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");  
  19.  
  20. startActivity(it);   

 

21.调用系统编辑添加联系人(全有效):

 
   
  1. Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);   
  2.  
  3. intent.setType(People.CONTENT_ITEM_TYPE);   
  4.  
  5. intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");   
  6.  
  7. intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");  
  8.  
  9. intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);   
  10.  
  11. intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");  
  12.  
  13. intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,                    Contacts.ContactMethodsColumns.TYPE_WORK);  
  14.  
  15. startActivity(intent);   

转载自:http://www.cnblogs.com/pandans/archive/2010/11/12.html

如果你想查看Intent大全,请参考:http://www.openintents.org/en/intentstable