Android之调用其他程序

来源:互联网 发布:程序员怎么赚钱 知乎 编辑:程序博客网 时间:2024/05/05 07:05

包括调用系统程序和第三方程序

0.调用第三方程序

[java] view plaincopy
  1. //方法一  
  2. Intent intent=new Intent();  
  3. //包名 包名+类名(全路径)  
  4. intent.setClassName("com.linxcool""com.linxcool.PlaneActivity");  
  5. startActivity(intent);  
  6. //方法二  
  7. Intent intent = new Intent();  
  8. ComponentName comp = new ComponentName("com.linxcool","com.linxcool.PlaneActivity");  
  9. intent.setComponent(comp);  
  10. intent.setAction("android.intent.action.MAIN");  
  11. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  12. startActivity(intent);    
[java] view plaincopy
  1. //方法一  
  2. Intent intent=new Intent();  
  3. //包名 包名+类名(全路径)  
  4. intent.setClassName("com.linxcool""com.linxcool.PlaneActivity");  
  5. startActivity(intent);  
  6. //方法二  
  7. Intent intent = new Intent();  
  8. ComponentName comp = new ComponentName("com.linxcool","com.linxcool.PlaneActivity");  
  9. intent.setComponent(comp);  
  10. intent.setAction("android.intent.action.MAIN");  
  11. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  12. startActivity(intent);    

1.从google搜索内容

[java] view plaincopy
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_WEB_SEARCH);  
  3. intent.putExtra(SearchManager.QUERY,"搜索内容")  
  4. startActivity(intent);  
[java] view plaincopy
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_WEB_SEARCH);  
  3. intent.putExtra(SearchManager.QUERY,"搜索内容")  
  4. startActivity(intent);  

2.浏览网页

[java] view plaincopy
  1. Uri uri =Uri.parse("http://www.google.com");  
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);  
  3. startActivity(it);  
[java] view plaincopy
  1. Uri uri =Uri.parse("http://www.google.com");  
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);  
  3. startActivity(it);  

3.显示地图

[java] view plaincopy
  1. Uri uri = Uri.parse("geo:38.899533,-77.036476");  
  2. Intent it = newIntent(Intent.Action_VIEW,uri);  
  3. startActivity(it);  
[java] view plaincopy
  1. Uri uri = Uri.parse("geo:38.899533,-77.036476");  
  2. Intent it = newIntent(Intent.Action_VIEW,uri);  
  3. startActivity(it);  

4.路径规划

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

5.拨打电话

[java] view plaincopy
  1. Uri uri =Uri.parse("tel:xxxxxx");  
  2. Intent it = new Intent(Intent.ACTION_DIAL,uri);    
  3. startActivity(it);  
[java] view plaincopy
  1. Uri uri =Uri.parse("tel:xxxxxx");  
  2. Intent it = new Intent(Intent.ACTION_DIAL,uri);    
  3. startActivity(it);  

6.发短信

[java] view plaincopy
  1. //方法1:  
  2. Intent it = newIntent(Intent.ACTION_VIEW);     
  3. it.putExtra("sms_body""TheSMS text");     
  4. it.setType("vnd.android-dir/mms-sms");     
  5. startActivity(it);  
  6.   
  7. //方法2:  
  8. Uri uri =Uri.parse("smsto:0800000123");     
  9. Intent it = newIntent(Intent.ACTION_SENDTO, uri);     
  10. it.putExtra("sms_body""TheSMS text");     
  11. startActivity(it);  
  12.   
  13. //方法三:  
  14. String body="this is sms demo";  
  15. Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));  
  16. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);  
  17. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);  
  18. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);  
  19. startActivity(mmsintent);  
[java] view plaincopy
  1. //方法1:  
  2. Intent it = newIntent(Intent.ACTION_VIEW);     
  3. it.putExtra("sms_body""TheSMS text");     
  4. it.setType("vnd.android-dir/mms-sms");     
  5. startActivity(it);  
  6.   
  7. //方法2:  
  8. Uri uri =Uri.parse("smsto:0800000123");     
  9. Intent it = newIntent(Intent.ACTION_SENDTO, uri);     
  10. it.putExtra("sms_body""TheSMS text");     
  11. startActivity(it);  
  12.   
  13. //方法三:  
  14. String body="this is sms demo";  
  15. Intent mmsintent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));  
  16. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);  
  17. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);  
  18. mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);  
  19. startActivity(mmsintent);  

7.发送彩信

[java] view plaincopy
  1. Uri uri =Uri.parse("content://media/external/images/media/23");     
  2. Intent it = newIntent(Intent.ACTION_SEND);     
  3. it.putExtra("sms_body","some text");     
  4. it.putExtra(Intent.EXTRA_STREAM, uri);     
  5. it.setType("image/png");     
  6. startActivity(it);  
  7. StringBuilder sb = new StringBuilder();  
  8. sb.append("file://");  
  9. sb.append(fd.getAbsoluteFile());  
  10. Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));  
  11. // Below extra datas are all optional.  
  12. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);  
  13. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);  
  14. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());  
  15. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);  
  16. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);  
  17. startActivity(intent);  
[java] view plaincopy
  1. Uri uri =Uri.parse("content://media/external/images/media/23");     
  2. Intent it = newIntent(Intent.ACTION_SEND);     
  3. it.putExtra("sms_body","some text");     
  4. it.putExtra(Intent.EXTRA_STREAM, uri);     
  5. it.setType("image/png");     
  6. startActivity(it);  
  7. StringBuilder sb = new StringBuilder();  
  8. sb.append("file://");  
  9. sb.append(fd.getAbsoluteFile());  
  10. Intent intent = newIntent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));  
  11. // Below extra datas are all optional.  
  12. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);  
  13. intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);  
  14. intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString());  
  15. intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);  
  16. intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);  
  17. startActivity(intent);  
8.发送Email
[java] view plaincopy
  1. Uri uri =Uri.parse("mailto:xxx@abc.com");  
  2. Intent it = newIntent(Intent.ACTION_SENDTO, uri);  
  3. startActivity(it);  
  4.   
  5. Intent it = new Intent(Intent.ACTION_SEND);     
  6. it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");     
  7. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");     
  8. it.setType("text/plain");     
  9. startActivity(Intent.createChooser(it,"Choose Email Client"));  
  10.   
  11. Intent it=new Intent(Intent.ACTION_SEND);       
  12. String[] tos={"me@abc.com"};       
  13. String[]ccs={"you@abc.com"};       
  14. it.putExtra(Intent.EXTRA_EMAIL, tos);       
  15. it.putExtra(Intent.EXTRA_CC, ccs);       
  16. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");       
  17. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");       
  18. it.setType("message/rfc822");       
  19. startActivity(Intent.createChooser(it,"Choose Email Client"));     
  20.   
  21. Intent it = newIntent(Intent.ACTION_SEND);     
  22. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");      
  23. it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");     
  24. sendIntent.setType("audio/mp3");     
  25. startActivity(Intent.createChooser(it,"Choose Email Client"));  
[java] view plaincopy
  1. Uri uri =Uri.parse("mailto:xxx@abc.com");  
  2. Intent it = newIntent(Intent.ACTION_SENDTO, uri);  
  3. startActivity(it);  
  4.   
  5. Intent it = new Intent(Intent.ACTION_SEND);     
  6. it.putExtra(Intent.EXTRA_EMAIL,"me@abc.com");     
  7. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");     
  8. it.setType("text/plain");     
  9. startActivity(Intent.createChooser(it,"Choose Email Client"));  
  10.   
  11. Intent it=new Intent(Intent.ACTION_SEND);       
  12. String[] tos={"me@abc.com"};       
  13. String[]ccs={"you@abc.com"};       
  14. it.putExtra(Intent.EXTRA_EMAIL, tos);       
  15. it.putExtra(Intent.EXTRA_CC, ccs);       
  16. it.putExtra(Intent.EXTRA_TEXT, "Theemail body text");       
  17. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");       
  18. it.setType("message/rfc822");       
  19. startActivity(Intent.createChooser(it,"Choose Email Client"));     
  20.   
  21. Intent it = newIntent(Intent.ACTION_SEND);     
  22. it.putExtra(Intent.EXTRA_SUBJECT, "Theemail subject text");      
  23. it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");     
  24. sendIntent.setType("audio/mp3");     
  25. startActivity(Intent.createChooser(it,"Choose Email Client"));  

9.播放多媒体 

[java] view plaincopy
  1. Intent it = new Intent(Intent.ACTION_VIEW);  
  2. Uri uri =Uri.parse("file:///sdcard/song.mp3");  
  3. it.setDataAndType(uri,"audio/mp3");  
  4. startActivity(it);  
  5. Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");     
  6. Intent it = new Intent(Intent.ACTION_VIEW,uri);     
  7. startActivity(it);  
[java] view plaincopy
  1. Intent it = new Intent(Intent.ACTION_VIEW);  
  2. Uri uri =Uri.parse("file:///sdcard/song.mp3");  
  3. it.setDataAndType(uri,"audio/mp3");  
  4. startActivity(it);  
  5. Uri uri =Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");     
  6. Intent it = new Intent(Intent.ACTION_VIEW,uri);     
  7. startActivity(it);  

10.卸载 apk

[java] view plaincopy
  1. Uri uri =Uri.fromParts("package", strPackageName, null);     
  2. Intent it = newIntent(Intent.ACTION_DELETE, uri);     
  3. startActivity(it);  
[java] view plaincopy
  1. Uri uri =Uri.fromParts("package", strPackageName, null);     
  2. Intent it = newIntent(Intent.ACTION_DELETE, uri);     
  3. startActivity(it);  

11.安装 apk

[java] view plaincopy
  1. Uri installUri = Uri.fromParts("package","xxx"null);  
  2. returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);  
  3.   
  4. Intent intent = new Intent(Intent.ACTION_VIEW);  
  5. intent.setDataAndType(Uri.parse("file://" + filepath),"application/vnd.android.package-archive");  
  6. startActivity(intent);// 安装  
[java] view plaincopy
  1. Uri installUri = Uri.fromParts("package","xxx"null);  
  2. returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);  
  3.   
  4. Intent intent = new Intent(Intent.ACTION_VIEW);  
  5. intent.setDataAndType(Uri.parse("file://" + filepath),"application/vnd.android.package-archive");  
  6. startActivity(intent);// 安装  

12. 打开照相机

[java] view plaincopy
  1. //1  
  2. Intent intent = new Intent("android.media.action.STILL_IMAGE_CAMERA"); //调用照相机  
  3. startActivity(intent);  
  4. //2  
  5. Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);  
  6. this.sendBroadcast(i);  
  7. //3  
  8. long dateTaken = System.currentTimeMillis();  
  9. String name = createName(dateTaken) + ".jpg";  
  10. fileName = folder + name;  
  11. ContentValues values = new ContentValues();  
  12. values.put(Images.Media.TITLE, fileName);  
  13. values.put("_data", fileName);  
  14. values.put(Images.Media.PICASA_ID, fileName);  
  15. values.put(Images.Media.DISPLAY_NAME, fileName);  
  16. values.put(Images.Media.DESCRIPTION, fileName);  
  17. values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);  
  18. Uri photoUri = getContentResolver().insert(  
  19. MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);  
  20.   
  21. Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  22. inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);  
  23. startActivityForResult(inttPhoto, 10);  
[java] view plaincopy
  1. //1  
  2. Intent intent = new Intent("android.media.action.STILL_IMAGE_CAMERA"); //调用照相机  
  3. startActivity(intent);  
  4. //2  
  5. Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);  
  6. this.sendBroadcast(i);  
  7. //3  
  8. long dateTaken = System.currentTimeMillis();  
  9. String name = createName(dateTaken) + ".jpg";  
  10. fileName = folder + name;  
  11. ContentValues values = new ContentValues();  
  12. values.put(Images.Media.TITLE, fileName);  
  13. values.put("_data", fileName);  
  14. values.put(Images.Media.PICASA_ID, fileName);  
  15. values.put(Images.Media.DISPLAY_NAME, fileName);  
  16. values.put(Images.Media.DESCRIPTION, fileName);  
  17. values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);  
  18. Uri photoUri = getContentResolver().insert(  
  19. MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);  
  20.   
  21. Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  22. inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);  
  23. startActivityForResult(inttPhoto, 10);  

13.从gallery选取图片

[java] view plaincopy
  1. Intent i = new Intent();  
  2. i.setType("image/*");  
  3. i.setAction(Intent.ACTION_GET_CONTENT);  
  4. startActivityForResult(i, 11);  
[java] view plaincopy
  1. Intent i = new Intent();  
  2. i.setType("image/*");  
  3. i.setAction(Intent.ACTION_GET_CONTENT);  
  4. startActivityForResult(i, 11);  

14. 打开录音机

[java] view plaincopy
  1. Intent mi = new Intent(Media.RECORD_SOUND_ACTION);  
  2. startActivity(mi);  
[java] view plaincopy
  1. Intent mi = new Intent(Media.RECORD_SOUND_ACTION);  
  2. startActivity(mi);  

15.显示应用详细列表

[java] view plaincopy
  1. Uri uri =Uri.parse("market://details?id=app_id");          
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);          
  3. startActivity(it);          
  4. //where app_id is the application ID, findthe ID           
  5. //by clicking on your application on Markethome           
  6. //page, and notice the ID from the addressbar  
  7. //发现用package name也可以  
  8. //Uri uri =Uri.parse("market://details?id=<packagename>");  
[java] view plaincopy
  1. Uri uri =Uri.parse("market://details?id=app_id");          
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);          
  3. startActivity(it);          
  4. //where app_id is the application ID, findthe ID           
  5. //by clicking on your application on Markethome           
  6. //page, and notice the ID from the addressbar  
  7. //发现用package name也可以  
  8. //Uri uri =Uri.parse("market://details?id=<packagename>");  

16.寻找应用

[java] view plaincopy
  1. Uri uri =Uri.parse("market://search?q=pname:pkg_name");          
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);          
  3. startActivity(it);  
  4. //where pkg_name is the full package pathfor an application    
[java] view plaincopy
  1. Uri uri =Uri.parse("market://search?q=pname:pkg_name");          
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);          
  3. startActivity(it);  
  4. //where pkg_name is the full package pathfor an application    

17.打开联系人列表

[java] view plaincopy
  1. //1             
  2. Intent i = new Intent();  
  3. i.setAction(Intent.ACTION_GET_CONTENT);  
  4. i.setType("vnd.android.cursor.item/phone");  
  5. startActivityForResult(i, REQUEST_TEXT);  
  6. //2  
  7. Uri uri = Uri.parse("content://contacts/people");  
  8. Intent it = new Intent(Intent.ACTION_PICK, uri);  
  9. startActivityForResult(it, REQUEST_TEXT);  
[java] view plaincopy
  1. //1             
  2. Intent i = new Intent();  
  3. i.setAction(Intent.ACTION_GET_CONTENT);  
  4. i.setType("vnd.android.cursor.item/phone");  
  5. startActivityForResult(i, REQUEST_TEXT);  
  6. //2  
  7. Uri uri = Uri.parse("content://contacts/people");  
  8. Intent it = new Intent(Intent.ACTION_PICK, uri);  
  9. startActivityForResult(it, REQUEST_TEXT);  

18.调用系统编辑添加联系人

[java] view plaincopy
  1. Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);  
  2. intent.setType(People.CONTENT_ITEM_TYPE);  
  3. intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");  
  4. intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");  
  5. intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);  
  6. intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");  
  7. intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);  
  8. startActivity(intent);  
[java] view plaincopy
  1. Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);  
  2. intent.setType(People.CONTENT_ITEM_TYPE);  
  3. intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");  
  4. intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");  
  5. intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);  
  6. intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");  
  7. intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);  
  8. startActivity(intent);  
0 0
原创粉丝点击