概述
最近在项目中用到了两个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);
- <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.卸载APK
- 01.Uri uri = Uri.fromParts("package", strPackageName, null);
- 02.Intent it = new Intent(Intent.ACTION_DELETE, uri);
- 03.startActivity(it);
10.打开照相机
- <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><div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><strong>[java]</strong> <a target=_blank class="ViewSource" title="view plain" href="http://blog.csdn.net/jamin0107/article/details/7047648#">view plain</a><a target=_blank class="CopyToClipboard" title="copy" href="http://blog.csdn.net/jamin0107/article/details/7047648#">copy</a><a target=_blank class="PrintSource" title="print" href="http://blog.csdn.net/jamin0107/article/details/7047648#">print</a><a target=_blank class="About" title="?" href="http://blog.csdn.net/jamin0107/article/details/7047648#">?</a></div></div><ol class="dp-j"><li class="alt"><span><span> </span></span></li></ol></div><pre style="DISPLAY: none" class="java" name="code">
- <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);
最后
以上就是深情中心为你收集整理的Intent大全,随用随更新 .的全部内容,希望文章能够帮你解决Intent大全,随用随更新 .所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复