Android常用Intent使用代码汇总:

显示网页:

[java] view plain copy
  1. 1.Uriuri=Uri.parse("http://www.google.com");
  2. 2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
  3. 3.startActivity(it);
显示地图:
[java] view plain copy
  1. 1.Uriuri=Uri.parse("geo:38.899533,-77.036476");
  2. 2.Intentit=newIntent(Intent.Action_VIEW,uri);
  3. 3.startActivity(it);
路径规划:
[java] view plain copy
  1. 1.Uriuri=Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
  2. 2.Intentit=newIntent(Intent.ACTION_VIEW,URI);
  3. 3.startActivity(it);
拨打电话:
调用拨号程序
[java] view plain copy
  1. 1.Uriuri=Uri.parse("tel:xxxxxx");
  2. 2.Intentit=newIntent(Intent.ACTION_DIAL,uri);
  3. 3.startActivity(it);
  4. 1.Uriuri=Uri.parse("tel.xxxxxx");
  5. 2.Intentit=newIntent(Intent.ACTION_CALL,uri);
  6. 3.要使用这个必须在配置文件中加入<uses-permissionid="android.permission.CALL_PHONE"/>
发送SMS/MMS
调用发送短信的程序
[java] view plain copy
  1. 1.Intentit=newIntent(Intent.ACTION_VIEW);
  2. 2.it.putExtra("sms_body","TheSMStext");
  3. 3.it.setType("vnd.android-dir/mms-sms");
  4. 4.startActivity(it);
发送短信

[java] view plain copy
  1. 1.Uriuri=Uri.parse("smsto:0800000123");
  2. 2.Intentit=newIntent(Intent.ACTION_SENDTO,uri);
  3. 3.it.putExtra("sms_body","TheSMStext");
  4. 4.startActivity(it);
发送彩信

[java] view plain copy
  1. 1.Uriuri=Uri.parse("content://media/external/images/media/23");
  2. 2.Intentit=newIntent(Intent.ACTION_SEND);
  3. 3.it.putExtra("sms_body","sometext");
  4. 4.it.putExtra(Intent.EXTRA_STREAM,uri);
  5. 5.it.setType("image/png");
  6. 6.startActivity(it);
发送Email
[java] view plain copy
  1. 1.
  2. 2.Uriuri=Uri.parse("mailto:[email protected]");
  3. 3.Intentit=newIntent(Intent.ACTION_SENDTO,uri);
  4. 4.startActivity(it);
  5. 1.Intentit=newIntent(Intent.ACTION_SEND);
  6. 2.it.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
  7. 3.it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
  8. 4.it.setType("text/plain");
  9. 5.startActivity(Intent.createChooser(it,"ChooseEmailClient"));
  10. 1.Intentit=newIntent(Intent.ACTION_SEND);
  11. 2.String[]tos={"[email protected]"};
  12. 3.String[]ccs={"[email protected]"};
  13. 4.it.putExtra(Intent.EXTRA_EMAIL,tos);
  14. 5.it.putExtra(Intent.EXTRA_CC,ccs);
  15. 6.it.putExtra(Intent.EXTRA_TEXT,"Theemailbodytext");
  16. 7.it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
  17. 8.it.setType("message/rfc822");
  18. 9.startActivity(Intent.createChooser(it,"ChooseEmailClient"));
添加附件
[java] view plain copy
  1. 1.Intentit=newIntent(Intent.ACTION_SEND);
  2. 2.it.putExtra(Intent.EXTRA_SUBJECT,"Theemailsubjecttext");
  3. 3.it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/mysong.mp3");
  4. 4.sendIntent.setType("audio/mp3");
  5. 5.startActivity(Intent.createChooser(it,"ChooseEmailClient"));
播放多媒体
[java] view plain copy
  1. 1.
  2. 2.Intentit=newIntent(Intent.ACTION_VIEW);
  3. 3.Uriuri=Uri.parse("file:///sdcard/song.mp3");
  4. 4.it.setDataAndType(uri,"audio/mp3");
  5. 5.startActivity(it);
  6. 1.Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
  7. 2.Intentit=newIntent(Intent.ACTION_VIEW,uri);
  8. 3.startActivity(it);
Uninstall 程序
[java] view plain copy
  1. 1.Uriuri=Uri.fromParts("package",strPackageName,null);
  2. 2.Intentit=newIntent(Intent.ACTION_DELETE,uri);
  3. 3.startActivity(it);

调用相册

[java] view plain copy
  1. publicstaticfinalStringMIME_TYPE_IMAGE_JPEG="image/*";
  2. publicstaticfinalintACTIVITY_GET_IMAGE=0;
  3. IntentgetImage=newIntent(Intent.ACTION_GET_CONTENT);
  4. getImage.addCategory(Intent.CATEGORY_OPENABLE);
  5. getImage.setType(MIME_TYPE_IMAGE_JPEG);
  6. startActivityForResult(getImage,ACTIVITY_GET_IMAGE);

调用系统相机应用程序,并存储拍下来的照片

[java] view plain copy
  1. Intentintent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
  2. time=Calendar.getInstance().getTimeInMillis();
  3. intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(newFile(Environment
  4. .getExternalStorageDirectory().getAbsolutePath()+"/tucue",time+".jpg")));
  5. startActivityForResult(intent,ACTIVITY_GET_CAMERA_IMAGE);

安装指定apk

[java]view plaincopy

  1. publicvoidsetupAPK(Stringapkname){
  2. StringfileName=Environment.getExternalStorageDirectory()+"/"+apkname;
  3. Intentintent=newIntent(Intent.ACTION_VIEW);
  4. intent.setDataAndType(Uri.fromFile(newFile(fileName)),"application/vnd.android.package-archive");
  5. mService.startActivity(intent);
  6. }

跳转至系统联系人界面,显示所有联系人

[java] view plain copy
  1. Intentintent=newIntent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);
  2. startActivity(intent);

更多相关文章

  1. Android(安卓)Permission中英对照
  2. 读取Android联系人列表
  3. Android的常用方法(转载)
  4. Android(安卓)编译系统 --- 版本信息
  5. android应用中调用系统相应用汇总
  6. [转]Android虚拟电源管理驱动
  7. android 手机系统日期及时间的读取
  8. Android(安卓)WebView在4.4版本以上无法获取高度
  9. android root权限相关bin程序rageagainsttheca

随机推荐

  1. 解决Conversion to Dalvik format failed
  2. android 开源自组织网络开源包
  3. 今天玩玩Android -==-- 了解一下
  4. 如何在Android单元测试中调试async-http
  5. Android小代码——设置全屏
  6. Android 获取电池电量
  7. 控件_AnalogClock
  8. Android中RadioGroup RadioButton CheckB
  9. 【Android】Activity与服务Service绑定
  10. android手机短信总结