Android Intent的几种使用方法全面总结
Intent应该算是Android中特有的东西。你能够在Intent中指定程序要运行的动作(比方:view,edit,dial),以及程序运行到该动作时所须要的资料。都指定好后,仅仅要调用startActivity(),Android系统会自己主动寻找最符合你指定要求的应用程序,并运行该程序。
以下列出几种Intent的使用方法
显示网页: Uri uri = Uri.parse("http://www.google.com"); Intent it = new Intent(Intent.ACTION_VIEW,uri); startActivity(it);
显示地图: Uri uri = Uri.parse("geo:38.899533,-77.036476"); Intent it = new Intent(Intent.Action_VIEW,uri); startActivity(it);
路径规划:
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);
拨打电话:
调用拨号程序
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);  
startActivity(it);  
Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
要使用这个必须在配置文件里增加<uses-permission id="android.permission.CALL_PHONE" /
发送SMS/MMS
调用发送短信的程序
Intent it = new Intent(Intent.ACTION_VIEW);   
it.putExtra("sms_body", "The SMS text");   
it.setType("vnd.android-dir/mms-sms");   
startActivity(it);
发送短信
Uri uri = Uri.parse("smsto:0800000123");   
Intent it = new Intent(Intent.ACTION_SENDTO, uri);   
it.putExtra("sms_body", "The SMS text");   
startActivity(it); 
发送彩信
Uri uri = Uri.parse("content://media/external/images/media/23");   
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);   
it.setType("image/png");   
startActivity(it);
发送Email
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");   
it.putExtra(Intent.EXTRA_TEXT, "The email body text");   
it.setType("text/plain");   
startActivity(Intent.createChooser(it, "Choose Email Client"));  
Intent it=new Intent(Intent.ACTION_SEND);     
String[] tos={"me@abc.com"};
String[] ccs={"you@abc.com"};     
it.putExtra(Intent.EXTRA_EMAIL, tos);     
it.putExtra(Intent.EXTRA_CC, ccs);     
it.putExtra(Intent.EXTRA_TEXT, "The email body text");     
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");     
it.setType("message/rfc822");     
startActivity(Intent.createChooser(it, "Choose Email Client"));   
加入附件
Intent it = new Intent(Intent.ACTION_SEND);   
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");   
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");   
sendIntent.setType("audio/mp3");   
startActivity(Intent.createChooser(it, "Choose Email Client"));
播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
Uninstall 程序
Uri uri = Uri.fromParts("package", strPackageName, null);   
Intent it = new Intent(Intent.ACTION_DELETE, uri);   
startActivity(it);
install apk
- Uri installUri = Uri.fromParts("package", "xxx", null);
2.returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
play audio
- Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
- returnIt = new Intent(Intent.ACTION_VIEW, playUri);
发送附件
- Intent it = new Intent(Intent.ACTION_SEND);
- it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
- it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");
- sendIntent.setType("audio/mp3");
- startActivity(Intent.createChooser(it, "Choose Email Client"));
market相关
//搜索应用
Uri uri = Uri.parse("market://search?q=pname:pkg_name");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where pkg_name is the full package path for an application
//显示指定应用的具体页面(这个好像不支持了,找不到app_id)
Uri uri = Uri.parse("market://details?id=app_id");  
Intent it = new Intent(Intent.ACTION_VIEW, uri);  
startActivity(it);  
//where app_id is the application ID, find the ID  
//by clicking on your application on Market home  
//page, and notice the ID from the address bar
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);
Android Intent的几种使用方法全面总结的更多相关文章
- Android Intent的几种用法全面总结
		Android Intent的几种用法全面总结 Intent, 用法 Intent应该算是Android中特有的东西.你可以在Intent中指定程序要执行的动作(比如:view,edit,dial), ... 
- android studio gradle 两种更新方法更新
		android studio gradle 两种更新方法更新 第一种.Android studio更新 第一步:在你所在项目文件夹下:你项目根目录gradlewrappergradle-wrapper ... 
- android intent打开各种文件的方法
		android intent打开各种文件的方法 1./** * 检测是否安装了某个软件 * * @param pkgName "com.bill99.kuaishua" ... 
- Android 广播机制(两种注册方法)与中断广播
		两种注册类型的区别是: 1)第一种不是常驻型广播,也就是说广播跟随activity的生命周期.注意: 在activity结束前,移除广播接收器. 2)第二种是常驻型,也就是说当应用程序关闭后,如果有信 ... 
- Intent的4种传值方法总结
		xml 代码: <Button android:id="@+id/button1" android:layout_width="wrap_conte ... 
- Android Intent的几种用法总结【转】
		Intent应该算是Android中特有的东西.你可以在Intent中指定程序要执行的动作(比如:view,edit,dial),以及程序执行到该动作时所需要的资料.都指定好后,只要调用startAc ... 
- Android 线程 thread 两种实现方法
		原文链接: http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thr ... 
- Android—— 线程 thread 两种实现方法!(转)
		原文地址:http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thre ... 
- Android 延时执行任务的三种简单方法
		开启一个新的线程 new Thread() { @Override public void run() { try { Thread.sleep(2000); } catch (Interrupted ... 
随机推荐
- GoF——职责链模式
			职责链模式(chain of Responsibility):使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它 ... 
- latex列表
			枚举.列举和描述 \begin{list_type} \item The first item \item The second item \item The third etc \ldots\end ... 
- 自定义构造、description方法、SEL
			[Objective-C]07-自定义构造方法和description方法 // 构造方法:用来初始化对象的方法,是个对象方法,”-"开头// 重写构造方法的目的:为了让对象创建出来,成 ... 
- mini KMS Activator v1.3破解激活microsoft Office 2010 RTM
			利用mini KMS Activator v1.3破解激活microsoft Office 2010 RTM方法,只是为体验office而做测试使用的哦...大家觉得好就自觉购买正版去... 使用步骤 ... 
- 04737_C++程序设计_第8章_多态性和虚函数
			例8.1 分析下面程序的输出结果. 例8.2 分别使用指针和引用的display函数. #include <iostream> using namespace std; const dou ... 
- 执行startx后Ubuntupassword正确进不去的问题
			今天在命令行里敲了 startx ,然后系统重新启动.输入password后,跳转到一下界面.之后又返回到登陆界面.一直这样循环输入password.进不去系统. 然后不得不用手机在网上查找解决的方法 ... 
- SPDY HTTP2.0
			SPDY(读作“SPeeDY”)是Google开发的基于TCP的应用层协议,用以最小化网络延迟,提升网络速度,优化用户的网络使用体验.SPDY并不是一种用于替代HTTP的协议,而是对HTTP协议的增强 ... 
- English - when用法
			一.作为副词,它有以下的用法: 1. 作为疑问副词,引导特殊疑问句,意为“什么时候:何时”.如: ( 1 ) When will they come back?( 2 ) What time wil ... 
- C++中常用特殊符号简介(& , * , : , :: , ->)
			1."&"一般表示:引用,按位与,取地址. 如: class Complex { public: Complex operator+(Complex &c2) .. ... 
- 完全卸载oracle10G/11G步骤
			从oracle前台卸载oracle后重新安装会安装不了,需要完全卸载: 完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle ... 
