intent 大全

最近在项目中用到了两个Intent,顺便起个帖总结一下,虽然这些东西看起来都简单,不过有时候用的时候很容易忘,不废话,直接上图上代码.用的时候一目了然.

1.添加联系人.

  1. <span style="font-size:16px;">    Intent intent = new Intent(Intent.ACTION_INSERT,  
  2.             Contacts.CONTENT_URI);  
  3.     intent.putExtra("name""wang");  
  4.     intent.putExtra("phone""158");          
  5.     startActivity(intent);    
  6. </span>  



2.添加联系人,跳转到新增或合并页面,点击已有联系人则进行合并.下面intent传送数据时的键,最好用android给好的,不要像上面那么用.

(高版本)

  1. Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);  
  2.                it.setType("vnd.android.cursor.item/contact");  
  3.                 //it.setType(Contacts.CONTENT_ITEM_TYPE);  
  4.                 it.putExtra("name","myName");  
  5.                it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY,  "organization");  
  6.                it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");  
  7.                 it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");  
  8.                 it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,  
  9.                                "mobilePhone");  
  10.                 it.putExtra(  android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,  
  11.                                "workPhone");  
  12.                it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");  
  13.                 startActivity(it);  
(全部版本)
  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);  


3.打电话Intent(直接拨通),打电话的Intent有两种.第一种为直接拨通.

  1. <span style="font-size:16px;">    Intent callintent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:" + mobile));  
  2.     callintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  3.     startActivity(callintent);  
  4. </span>  


4.打电话的第二种Intent,跳转到拨号界面



  1. <span style="font-size:16px;">Intent callintent = new Intent(Intent.ACTION_DIAL , Uri.parse("tel:" + mobile));  
  2. callintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  3. startActivity(callintent);</span>  




5.发送Email


  1. <span style="font-size:16px;">    Uri uri = Uri.parse("mailto:"+ email);     
  2.     Intent emailintent = new Intent(Intent.ACTION_SENDTO, uri);     
  3.         startActivity(emailintent);  
  4. </span>  


6.发送短信


  1. <span style="font-size:16px;">    Intent mmsintent = new Intent(Intent.ACTION_SENDTO , Uri.parse("smsto:" + mobile));  
  2.     mmsintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  3.     startActivity(mmsintent);</span>  


7.显示地图


  1. <span style="font-size:16px;">        Uri uri = Uri.parse("geo:38.899533,-77.036476");   
  2.         Intent it = new Intent(Intent.Action_VIEW,uri);   
  3.         startActivity(it);</span>  

8.安装APK


  1. <span style="font-size:16px;">        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);// 安装</span>  

9.打开照相机

  1. <1> Intent intent = new Intent("android.media.action.STILL_IMAGE_CAMERA"); //调用照相机  
  2.       startActivity(intent);  
  3.   
  4. <2>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);  
  5.       this.sendBroadcast(i);  
  1. </pre><pre name="code" class="java">  
  1. </pre><pre name="code" class="java">    <3>long dateTaken = System.currentTimeMillis();  
  2.            String name = createName(dateTaken) + ".jpg";  
  3.            fileName = folder + name;  
  4.            ContentValues values = new ContentValues();  
  5.            values.put(Images.Media.TITLE, fileName);  
  6.            values.put("_data", fileName);  
  7.            values.put(Images.Media.PICASA_ID, fileName);  
  8.            values.put(Images.Media.DISPLAY_NAME, fileName);  
  9.            values.put(Images.Media.DESCRIPTION, fileName);  
  10.            values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);  
  11.            Uri photoUri = getContentResolver().insert(  
  12.                     MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);  
  13.    
  14.            Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  15.            inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);  
  16.            startActivityForResult(inttPhoto, 10);  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值