`
eagle0824
  • 浏览: 227703 次
  • 性别: Icon_minigender_1
  • 来自: 镇江
社区版块
存档分类
最新评论

android intent 常用用法

 
阅读更多

转自   http://www.cnblogs.com/lilactutu/archive/2010/12/03/1895537.html



Intent应该算是Android中特有的东西。你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料。都指定好后,只要调用 startActivity(),Android系统会自动寻找最符合你指定要求的应用程序,并执行该程序。

下面列出几种Intent的用法
显示网页:

   1. Uri uri = Uri.parse("http://www.google.com");
   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("http://maps.google.com/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. 要使用这个必须在配置文件中加入<uses-permission id="android.permission.CALL_PHONE" />

发送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:xxx@abc.com");
   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, "me@abc.com");
   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={"me@abc.com"};   
   3. String[] ccs={"you@abc.com"};   
   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);
分享到:
评论

相关推荐

    intent的常用方法

    intent的常用方法 Intent在Android中的几种用法 文章分类:综合技术

    详解Android中Intent的使用方法

    主要介绍了Android中Intent的使用方法,Android中的Intent是一个非常重要且常用的类,需要认真学习,感兴趣的小伙伴们可以参考一下

    Android常用的intent action汇总

    主要介绍了Android常用的intent action功能与用法,分析了intent的原理以及action属性常用动作名称、作用与使用方法,需要的朋友可以参考下

    Android开发中使用Intent打开第三方应用及验证可用性的方法详解

    主要介绍了Android开发中使用Intent打开第三方应用及验证可用性的方法,结合实例形式分析了Android使用Intent打开第三方应用的三种常用方式及使用注意事项,需要的朋友可以参考下

    Android应用开发详解

    Android开发基础,讲述了Android开发环境的搭建、Android常用工具的使用和第一个Android应用程序的开发 第二篇 技术篇 第3章 Android中的资源访问 Android 中的资源访问,讲述了如何定义和访问Android中的外部...

    疯狂Android讲义源代码2

    1.3 Android常用开发工具的用法 1.3.1 创建、删除和浏览AVD 1.3.2 使用Android模拟器(Emulator) 1.3.3 使用DDMS进行调试 1.3.4 Android Debug Bridge(ADB)的用法 1.3.5 使用DX编译Android应用 1.3.6 使用...

    新版Android开发教程.rar

    的 Android SDK 提供了在 Android 平台上使用 JaVa 语言进行 Android 应用开发必须的工具和 API 接口。 特性 • 应用程序框架 支持组件的重用与替换 • Dalvik Dalvik Dalvik Dalvik 虚拟机 专为移动设备优化 • ...

    培训时老师给的android资料 pdf格式的

    本想在csdn中找个更深入...书中比较详述的地介绍了android的常用组件的用法(包括事件)和intent以及google API中地图(GPS)的使用和数据库在android中3中使用方法等。可惜没有了更深一点的资料,这些只能说是入门用的

    Android UI组件实例集合

    使用方法:1-把GifView.jar加入你的项目。2-在xml中配置GifView的基本属性,GifView继承自View类,和Button、ImageView一样是一个UI控件。 如: &lt;com.ant.liao.GifView android:id="@+id/gif2" android:layout_...

    Android移动应用开发实验指导书.docx

    (3)掌握自定义控件的2种使用方法。 (4)掌握ListView的简单用法。 (5)掌握自定义ListView控件的使用。 实验软、硬件环境 硬件:PC电脑一台; 配置:winxp或win7系统,内存大于4G,硬盘250G及以上 JDK1.7 、...

    疯狂Android讲义源码

     1.3 Android常用开发工具的用法 10  1.3.1 创建、删除和浏览AVD 10  1.3.2 使用Android模拟器  (Emulator) 14  1.3.3 使用DDMS进行调试 15  1.3.4 Android Debug Bridge(ADB)  的用法 16  1.3.5 使用DX...

    Android开发与应用——张荣,原书配套课件

    5.3.1 使用Intent封装数据 5.3.2 使用Bundle封装数据 5.3.3 获取另一个界面返回结果 5.4 小结 练习 第6章 Android数据存储与共享 6.1 数据存储与共享方式概述 6.2 首选项信息 6.2.1 私有数据存储 ...

    Android开发案例驱动教程 配套代码

    3.3 使用Android SDK帮助 23 3.3.1 Android SDK API文档 23 3.3.2 Android SDK开发指南 24 3.3.3 Android SDK samples 24 3.4 使用DDMS帮助调试程序 26 3.4.1 启动DDMS 26 3.4.2 Device 28 3.4.3 Emulator ...

    Intent跳转和7个生命周期

    1.掌握Activity的创建和使用Intent跳转Activity。 2.掌握活动的生命周期,以及7个生命周期方法的作用。 Intent跳转 Android软件进行跳转最简单的运用,按钮的跳转活动的运用。 本次我们初步学习Intent跳转,通过按钮...

    Android常用对话框使用大全

    日常生活中我们随处可见对话框,上面有很多提示信息,更加方便提示用户进行不同的操作。 一、对话框的两个特点和一些常见的对话框 ...3.第三步调用create()方法来创建(一般自动调用) 4.第四步调用sh

    android 开发技巧合集

    0、ANDROID常用类库说明 6 1、ANDROID文件系统与应用程序架构 7 1.1、ANDROID 文件系统 7 1.2、ANDROID应用程序架构 9 2、ANDROID应用程序结构 11 2.1、ACTIVITY 12 2.1.1、概述 12 2.1.2、Activity的生命周期 15 ...

    Android移动应用开发实验指导书.docx.docx

    (3)掌握自定义控件的2种使用方法。 (4)掌握ListView的简单用法。 (5)掌握自定义ListView控件的使用。 实验软、硬件环境 硬件:PC电脑一台; 配置:winxp或win7系统,内存大于4G,硬盘250G及以上 JDK1.7 、...

    通用Android工具库Common4Android.zip

    Common4Android是一个通用Android工具库,包含网络库、线程管理器、常用Util工具、热修复,它拥有良好的架构,低耦合、高内聚,使用起来非常轻松。 -基类 ClassName Description ...

Global site tag (gtag.js) - Google Analytics