最近在项目中用到了两个Intent,顺便起个帖总结一下,虽然这些东西看起来都简单,不过有时候用的时候很容易忘,不废话,直接上图上代码.用的时候一目了然.
1.添加联系人.
- <span style="font-size:16px;"> Intent intent = new Intent(Intent.ACTION_INSERT,
- Contacts.CONTENT_URI);
- intent.putExtra("name", "wang");
- intent.putExtra("phone", "158");
- startActivity(intent);
- </span>
2.添加联系人,跳转到新增或合并页面,点击已有联系人则进行合并.下面intent传送数据时的键,最好用android给好的,不要像上面那么用.
(高版本)
- Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);
- it.setType("vnd.android.cursor.item/contact");
- //it.setType(Contacts.CONTENT_ITEM_TYPE);
- it.putExtra("name","myName");
- it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, "organization");
- it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");
- it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");
- it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
- "mobilePhone");
- it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
- "workPhone");
- it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");
- startActivity(it);
- Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);
- intent.setType(People.CONTENT_ITEM_TYPE);
- intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");
- intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
- intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
- intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");
- intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);
- startActivity(intent);
3.打电话Intent(直接拨通),打电话的Intent有两种.第一种为直接拨通.
- <span style="font-size:16px;"> Intent callintent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:" + mobile));
- callintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(callintent);
- </span>
4.打电话的第二种Intent,跳转到拨号界面
- <span style="font-size:16px;">Intent callintent = new Intent(Intent.ACTION_DIAL , Uri.parse("tel:" + mobile));
- callintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(callintent);</span>
5.发送Email
- <span style="font-size:16px;"> Uri uri = Uri.parse("mailto:"+ email);
- Intent emailintent = new Intent(Intent.ACTION_SENDTO, uri);
- startActivity(emailintent);
- </span>
6.发送短信
- <span style="font-size:16px;"> Intent mmsintent = new Intent(Intent.ACTION_SENDTO , Uri.parse("smsto:" + mobile));
- mmsintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(mmsintent);</span>
7.显示地图
- <span style="font-size:16px;"> Uri uri = Uri.parse("geo:38.899533,-77.036476");
- Intent it = new Intent(Intent.Action_VIEW,uri);
- startActivity(it);</span>
8.安装APK
- <span style="font-size:16px;"> Uri installUri = Uri.fromParts("package","xxx", null);
- returnIt = newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse("file://" + filepath),"application/vnd.android.package-archive");
- startActivity(intent);// 安装</span>
9.打开照相机
- <1> Intent intent = new Intent("android.media.action.STILL_IMAGE_CAMERA"); //调用照相机
- startActivity(intent);
- <2>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
- this.sendBroadcast(i);
- </pre><pre name="code" class="java">
- </pre><pre name="code" class="java"> <3>long dateTaken = System.currentTimeMillis();
- String name = createName(dateTaken) + ".jpg";
- fileName = folder + name;
- ContentValues values = new ContentValues();
- values.put(Images.Media.TITLE, fileName);
- values.put("_data", fileName);
- values.put(Images.Media.PICASA_ID, fileName);
- values.put(Images.Media.DISPLAY_NAME, fileName);
- values.put(Images.Media.DESCRIPTION, fileName);
- values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
- Uri photoUri = getContentResolver().insert(
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
- Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
- startActivityForResult(inttPhoto, 10);