Inent调用代码总结,不断完善中

显示Web网页:

  1. Uri uri = Uri.parse(“http://www.android123.com.cn”);
  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);
  3. startActivity(it);

显示Google地图:

  1. Uri uri = Uri.parse(“geo:38.899533,-77.036476”);
  2. Intent it = new Intent(Intent.Action_VIEW,uri);
  3. startActivity(it);

Maps路径规划:

  1. Uri uri = Uri.parse(“http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en”);
  2. Intent it = new Intent(Intent.ACTION_VIEW,URI);
  3. startActivity(it);

拨打电话:

  1. Uri uri = Uri.parse(“tel:xxxxxx”);

  2. Intent it = new Intent(Intent.ACTION_DIAL, uri);

  3. startActivity(it);

  4. Uri uri = Uri.parse(“tel.xxxxxx”);

  5. Intent it =new Intent(Intent.ACTION_CALL,uri);

注意需要权限

发送SMS/MMS

  1. Intent it = new Intent(Intent.ACTION_VIEW);
  2. it.putExtra(“sms_body”, “android开发网欢迎您”);
  3. it.setType(“vnd.android-dir/mms-sms”);
  4. startActivity(it);

发送短信

  1. Uri uri = Uri.parse(“smsto:10086”);
  2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
  3. it.putExtra(“sms_body”, “10086”); //正文为10086
  4. startActivity(it);

发送彩信

  1. Uri uri = Uri.parse(“content://media/external/images/media/10”); //该Uri根据实际情况修改,external代表外部存储即sdcard
  2. Intent it = new Intent(Intent.ACTION_SEND);
  3. it.putExtra(“sms_body”, “android123.com.cn”);
  4. it.putExtra(Intent.EXTRA_STREAM, uri);
  5. it.setType(“image/png”);
  6. startActivity(it);

发送Email

  1. Uri uri = Uri.parse(“mailto:[email protected]”);

  2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  3. startActivity(it);

  4. Intent it = new Intent(Intent.ACTION_SEND);

  5. it.putExtra(Intent.EXTRA_EMAIL, “[email protected]”);

  6. it.putExtra(Intent.EXTRA_TEXT, “android开发网测试”);

  7. it.setType(“text/plain”);

  8. startActivity(Intent.createChooser(it, “选择一个Email客户端”));

  9. Intent it=new Intent(Intent.ACTION_SEND);

  10. String tos={“[email protected]”}; //发送到

  11. String ccs={“[email protected]”}; //抄送

  12. it.putExtra(Intent.EXTRA_EMAIL, tos);

  13. it.putExtra(Intent.EXTRA_CC, ccs);

  14. it.putExtra(Intent.EXTRA_TEXT, “正文”);

  15. it.putExtra(Intent.EXTRA_SUBJECT, “标题”);

  16. it.setType(“message/rfc822”); //编码类型

  17. startActivity(Intent.createChooser(it, “选择一个Email客户端”));

Email添加附件

  1. Intent it = new Intent(Intent.ACTION_SEND);
  2. it.putExtra(Intent.EXTRA_SUBJECT, “正文”);
  3. it.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/nobody.mp3”); //附件为sd卡上的nobody MP3文件
  4. sendIntent.setType(“audio/mp3”);
  5. startActivity(Intent.createChooser(it, “选择一个Email客户端”));

播放多媒体

  1. Intent it = new Intent(Intent.ACTION_VIEW);

  2. Uri uri = Uri.parse(“file:///sdcard/nobody.mp3”);

  3. it.setDataAndType(uri, “audio/mp3”);

  4. startActivity(it);

  5. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, “1”); //从系统内部的MediaProvider索引中调用播放

  6. Intent it = new Intent(Intent.ACTION_VIEW, uri);

  7. startActivity(it);

Uninstall卸载程序

  1. Uri uri = Uri.fromParts(“package”, packageName, null); //packageName为包名,比如com.android123.apkInstaller
  2. Intent it = new Intent(Intent.ACTION_DELETE, uri);
  3. startActivity(it);