Android_Intent的几种用法全面总结.doc_第1页
Android_Intent的几种用法全面总结.doc_第2页
Android_Intent的几种用法全面总结.doc_第3页
Android_Intent的几种用法全面总结.doc_第4页
Android_Intent的几种用法全面总结.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

Android Intent的幾種用法全面總結Intent, 用法Intent应该算是Android中特有的东西。你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料。都指定好后,只要调用startActivity(),Android系统会自动寻找最符合你指定要求的应用程序,并执行该程序。下面列出几种Intent的用法显示网页: 1. Uri uri = Uri.parse();2. Intent it= new Intent(Intent.ACTION_VIEW,uri);3. startActivity(it); 复制代码显示地图: 1. Uri uri = Uri.parse(geo:38.899533,-77.036476);2. Intent it = new Intent(Intent.Action_VIEW,uri);3. startActivity(it); 复制代码路径规划: 1. Uri uri = Uri.parse(/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); 复制代码1. Uri uri = Uri.parse(tel.xxxxxx);2. Intent it =new Intent(Intent.ACTION_CALL,uri);3. 要使用这个必须在配置文件中加入 复制代码发送SMS/MMS调用发送短信的程序 1. Intent it = new Intent(Intent.ACTION_VIEW); 2. it.putExtra(sms_body, The SMS text); 3. it.setType(vnd.android-dir/mms-sms); 4. startActivity(it); 复制代码发送短信 1. Uri uri = Uri.parse(smsto:0800000123); 2. Intent it = new Intent(Intent.ACTION_SENDTO, uri); 3. it.putExtra(sms_body, The SMS text); 4. startActivity(it); 复制代码发送彩信 1. Uri uri = Uri.parse(content:/media/external/images/media/23); 2. Intent it = new Intent(Intent.ACTION_SEND); 3. it.putExtra(sms_body, some text); 4. it.putExtra(Intent.EXTRA_STREAM, uri); 5. it.setType(image/png); 6. startActivity(it); 复制代码发送Email 1.2. Uri uri = Uri.parse(mailto:);3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);4. startActivity(it); 复制代码1. Intent it = new Intent(Intent.ACTION_SEND); 2. it.putExtra(Intent.EXTRA_EMAIL, ); 3. it.putExtra(Intent.EXTRA_TEXT, The email body text); 4. it.setType(text/plain); 5. startActivity(Intent.createChooser(it, Choose Email Client); 复制代码1. Intent it=new Intent(Intent.ACTION_SEND); 2. String tos=; 3. String ccs=; 4. it.putExtra(Intent.EXTRA_EMAIL, tos); 5. it.putExtra(Intent.EXTRA_CC, ccs); 6. it.putExtra(Intent.EXTRA_TEXT, The email body text); 7. it.putExtra(Intent.EXTRA_SUBJECT, The email subject text); 8. it.setType(message/rfc822); 9. startActivity(Intent.createChooser(it, Choose Email Client); 复制代码添加附件 1. Intent it = new Intent(Intent.ACTION_SEND); 2. it.putExtra(Intent.EXTRA_SUBJECT, The email subject text); 3. it.putExtra(Intent.EXTRA_STREAM, file:/sdcard/mysong.mp3); 4. sendIntent.setType(audio/mp3); 5. startActivity(Intent.createChooser(it, Choose Email Client); 复制代码播放多媒体 1. 2. Intent it = new Intent(Intent.ACTION_VIEW);3. Uri uri = Uri.parse(file:/sdcard/song.mp3);4. it.setDataAndType(uri, audio/mp3);5. startActivity(it); 复制代码1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, 1); 2. Intent it = new Intent(Intent.ACTION_VIEW, uri); 3. startActivity(it); 复制代码Uninstall 程序 1. Uri uri = Uri.fromParts(package, strPackageName, null); 2. Intent it = new Intent(Intent.ACTION_DELETE, uri); 3. startActivity(it); 复制代码uninstall apk1. Uri uninstallUri = Uri.fromParts(package, xxx, null);2.3. returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri); 复制代码install apk1. Uri installUri = Uri.fromParts(package, xxx, null);2.3. returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri); 复制代码play audio1. Uri playUri = Uri.parse(file:/sdcard/download/everything.mp3);2.3. returnIt = new Intent(Intent.ACTION_VIEW, playUri); 复制代码1. /发送附件2. Intent it = new Intent(Intent.ACTION_SEND);3. it.putExtra(Intent.EXTRA_SUBJECT, The email subject text);4. it.putExtra(Intent.EXTRA_STREAM, file:/sdcard/eoe.mp3);5. sendIntent.setType(audio/mp3);6. startActivity(Intent.createChooser(it, Choose Email Client); 1. /搜索应用2. Uri uri = Uri.parse(market:/search?q=pname:pkg_name);3. Intent it = new Intent(Intent.ACTION_VIEW, uri);4. startActivity(it);5. /where pkg_name is the full package path for an application6.7. /显示指定应用的详细页面(这个好像不支持了,找不到app_id)8. Uri uri = Uri.parse(market:/details?id=app_id);9. Intent it = new Intent(Intent.ACTION_VIEW, uri);10. startActivity(it);11. /where app_id is the application ID, find the ID12. /by clicking on your application on Market home13. /page, and notice the ID from the address bar /*/*获得包安装Intent*paramtempFile*return*/publicstaticIntentgetPackageInstallIntent(FiletempFile)UrimPackageURI=Uri.fromFile(tempFile);Intentin=newIntent();in.setAction(Intent.ACTION_VIEW);in.addCategory(Intent.CATEGORY_DEFAULT);in.setCom

温馨提示

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

评论

0/150

提交评论