androidIntent使用技巧_第1页
androidIntent使用技巧_第2页
androidIntent使用技巧_第3页
androidIntent使用技巧_第4页
androidIntent使用技巧_第5页
免费预览已结束,剩余6页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、android 中 intent 是经常要用到的。不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到 intent。在做了一些 intent 的例子之后,整理了一下 intent,希望对大家有用。由于 intent 内容太多,不可能真的写全,难免会有遗落,以后我会随时更新。如果你们有疑问或新的 intent 内容,希望交流。intent 大全:1 .从 google 搜索内容Intentintent=newIntent();intent.setAction(Intent.ACTION_WEB_SEARCH);intent.putExtra(SearchManager.QUERY,

2、searchString)startActivity(intent);2 .浏览网页Uriuri=Uri.parse(http:/);Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);3 .显示地图Uriuri=Uri.parse(geo:38.899533,-77.036476);Intentit=newIntent(Intent.Action_VIEW,uri);startActivity(it);4 .路径规划Uriuri=Uri.parse(http:/ .拨打电话Uriuri=Uri.parse(tel:xxxx

3、xx);Intentit=newIntent(Intent.ACTION_DIAL,uri);startActivity(it);6 .调用发短信的程序Intentit=newIntent(Intent.ACTION_VIEW);it.putExtra(sms_body,TheSMStext);it.setType(vnd.android-dir/mms-sms);startActivity(it);7 .发送短信Uriuri=Uri.parse(smsto:0800000123);Intentit=newIntent(Intent.ACTION_SENDTO,uri);it.putExtra

4、(sms_body,TheSMStext);startActivity(it);Stringbody=thisissmsdemo;Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(smsto,mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);mmsintent.putExtra(Messaging.KEY_ACT

5、ION_SENDTO_EXIT_ON_SENT,true);startActivity(mmsintent);Uriuri=Uri.parse(content:/media/external/images/media/23);Intentit=newIntent(Intent.ACTION_SEND);it.putExtra(sms_body,sometext);it.putExtra(Intent.EXTRA_STREAM,uri);it.setType(image/png);number,null);startActivity(it);StringBuildersb=newStringBu

6、ilder();sb.append(file:/);sb.append(fd.getAbsoluteFile();Intentintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(mmsto,number,null);/Bent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);int

7、ent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString();intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,composeMode);intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,exitOnSent);startActivity(intent);9 .发送 EmailUriuri=Uri.parse(mailto:);Intentit=newIntent(Intent.ACTION_SE

8、NDTO,uri);startActivity(it);Intentit=newIntent(Intent.ACTION_SEND);it.putExtra(Intent.EXTRA_EMAIL,);it.putExtra(Intent.EXTRA_TEXT,Theemailbodytext);it.setType(text/plain);startActivity(Intent.createChooser(it,ChooseEmailClient);Intentit=newIntent(Intent.ACTION_SEND);Stringtos=;Stringccs=;it.putExtra

9、(Intent.EXTRA_EMAIL,tos);it.putExtra(Intent.EXTRA_CC,ccs);it.putExtra(Intent.EXTRA_TEXT,Theemailbodytext);it.putExtra(Intent.EXTRA_SUBJECT,Theemailsubjecttext);it.setType(message/rfc822);startActivity(Intent.createChooser(it,ChooseEmailClient);Intentit=newIntent(Intent.ACTION_SEND);it.putExtra(Inten

10、t.EXTRA_SUBJECT,Theemailsubjecttext);it.putExtra(Intent.EXTRA_STREAM,file:/sdcard/mysong.mp3);sendIntent.setType(audio/mp3);startActivity(Intent.createChooser(it,ChooseEmailClient);10 .播放多媒体Intentit=newIntent(Intent.ACTION_VIEW);Uriuri=Uri.parse(file:/sdcard/song.mp3);it.setDataAndType(uri,audio/mp3

11、);startActivity(it);Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,1);Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);11 .uninstallapkUriuri=Uri.fromParts(package,strPackageName,null);Intentit=newIntent(Intent.ACTION_DELETE,uri);startActivity(it);1.1 installapkU

12、riinstallUri=Uri.fromParts(package,xxx,null);returnIt=newIntent(Intent.ACTION_PACKAGE_ADDED,installUri);.打开照相机Intenti=newIntent(Intent.ACTION_CAMERA_BUTTON,null);this.sendBroadcast(i);longdateTaken=System.currentTimeMillis();Stringname=createName(dateTaken)+.jpg;fileName=folder+name;ContentValuesval

13、ues=newContentValues();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);UriphotoUri=

14、getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);IntentinttPhoto=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT,photoUri);startActivityForResult(inttPhoto,10);.从 gallery 选取图片Intenti=newIntent();i.setType(image/*);i.setAction(Inte

15、nt.ACTION_GET_CONTENT);startActivityForResult(i,11);.打开录音机Intentmi=newIntent(Media.RECORD_SOUND_ACTION);startActivity(mi);.显示应用详细列表Uriuri=Uri.parse(market:/details?id=app_id);Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);/whereapp_idistheapplicationID,findtheID/byclickingonyourapplica

16、tiononMarkethome/page,andnoticetheIDfromtheaddressbar刚才找 appid 未果,结果发现用 packagename 也可以Uriuri=Uri.parse(market:/details?id=);这个简单多了17 寻找应用Uriuri=Uri.parse(market:/search?q=pname:pkg_name);Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);/wherepkg_nameisthefullpackagepathforanapplication1

17、8 打开联系人列表Intenti=newIntent();i.setAction(Intent.ACTION_GET_CONTENT);i.setType(vnd.android.cursor.item/phone);startActivityForResult(i,REQUEST_TEXT);Uriuri=Uri.parse(content:/contacts/people);Intentit=newIntent(Intent.ACTION_PICK,uri);startActivityForResult(it,REQUEST_TEXT);Intenti=newIntent();Compon

18、entNamecn=newComponentName(com.yellowbook.android2,com.yellowbook.android2.AndroidSearch);i.setComponent(cn);i.setAction(ent.action.MAIN);startActivityForResult(i,RESULT_OK);.调用系统编辑添加联系人(高版本 SDKf 效):Intentit=newIntent(Intent.ACTION_INSERT_OR_EDIT);it.setType(vnd.android.cursor.item/contac

19、t);/it.setType(Contacts.CONTENT_ITEM_TYPE);it.putExtra(name,myName);it.putExtra(vider.Contacts.Intents.Insert.COMPANY,organization);it.putExtra(vider.Contacts.Intents.Insert.EMAIL,email);it.putExtra(vider.Contacts.Intents.Insert.PHONE,homePhone);it.putExtra(android.p

20、rovider.Contacts.Intents.Insert.SECONDARY_PHONE,mobilePhone);it.putExtra(vider.Contacts.Intents.Insert.TERTIARY_PHONE,workPhone);it.putExtra(vider.Contacts.Intents.Insert.JOB_TITLE,title);startActivity(it);.调用系统编辑添加联系人(全有效):Intentintent=newIntent(Intent.ACTION_INSERT_OR_EDIT);i

21、ntent.setType(People.CONTENT_ITEM_TYPE);intent.putExtra(Contacts.Intents.Insert.NAME,MyName);intent.putExtra(Contacts.Intents.Insert.PHONE,+1234567890);intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);intent.putExtra(Contacts.Intents.Insert.EMAIL,);intent.putExt

22、ra(Contacts.Intents.Insert.EMAIL_TYPE,Contacts.ContactMethodsColumns.TYPE_WORK);startActivity(intent);intentaction 大全:ent.action.ALL_APPSent.action.ANSWERent.action.ATTACH_DATAent.action.BUG_REPORTent.action.CALLent.action.CALL_BUTTON

23、ent.action.CHOOSERent.action.CREATE_LIVE_FOLDERent.action.CREATE_SHORTCUTent.action.DELETEent.action.DIALent.action.EDITent.action.INSERTent.action.INSERT_OR_EDITent.action.MAINent.action.ME

24、DIA_SEARCHent.action.PICKent.action.PICK_ACTIVITYent.action.RINGTONE_PICKERent.action.RUNent.action.SEARCHent.action.SEARCH_LONG_PRESSent.action.SENDent.action.SENDTOent.action.SET_WALLPAPERent.action.SYNCent.action.SYSTEM_TUTORIALent.action.VIEWent.action.VOICE_COMMANDent.action.WEB_SEARCH.wifi.PICK_WIFI_NETWORKandroid.settings.AIRPLANE_MODE_SETTINGSa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论