`
cenphoenix
  • 浏览: 160544 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

Intent一般应用

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

下面列出几种Intent的用法
显示网页:
Uri uri = Uri.parse( "<a href=" http: //www.google.com" target="_blank" rel="external">http://www.google.com</a>");   
Intent it  = new  Intent(Intent.ACTION_VIEW,uri);  
startActivity(it);  
Java代码 
Uri uri = Uri.parse("<a href="http://www.google.com" target="_blank" rel="external">http://www.google.com</a>");  
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);   
Java代码 
Uri uri = Uri.parse("geo:38.899533,-77.036476");  
Intent it = new Intent(Intent.Action_VIEW,uri);  
startActivity(it);   


路径规划:
Uri uri = Uri.parse( "<a href=" http: //maps.google.com/maps?f=d" target="_blank" rel="external">http://maps.google.com/maps?f=d</a>&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");   
  
Intent it = new  Intent(Intent.ACTION_VIEW,URI);  
  
startActivity(it);  
Java代码 
Uri  
uri = Uri.parse("<a href="http://maps.google.com/maps?f=d"  
target="_blank"  
rel="external">http://maps.google.com/maps?f=d</a>&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);   
Java代码 
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"  />  
Java代码 
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);  
Java代码 
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);  
Java代码 
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);   
Java代码 
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);  
Java代码 
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" ));  
Java代码 
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" ));   
Java代码 
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" ));  
Java代码 
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);  
Java代码 
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);  
Java代码 
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);  
Java代码 
Uri uri = Uri.fromParts("package", strPackageName, null);     
Intent it = new Intent(Intent.ACTION_Delete, uri);     
startActivity(it);  



uninstall apk
Uri uninstallUri = Uri.fromParts( "package" ,  "xxx" ,  null );  
returnIt = new  Intent(Intent.ACTION_Delete, uninstallUri);  
Java代码 
Uri uninstallUri = Uri.fromParts("package", "xxx", null);  
returnIt = new Intent(Intent.ACTION_Delete, uninstallUri);  



install apk
Uri installUri = Uri.fromParts( "package" ,  "xxx" ,  null );  
returnIt = new  Intent(Intent.ACTION_PACKAGE_ADDED, installUri);  
Java代码 
Uri installUri = Uri.fromParts("package", "xxx", null);  
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);  
Java代码 
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" ));  
Java代码 
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   
分享到:
评论

相关推荐

    java Intent的应用小例子

    在Android开发中,Intent是一种非常重要的组件,它用于在应用程序的不同组件之间传递消息,实现活动(Activity)之间的交互。Intent不仅用于启动新的Activity,还能启动服务(Service)或广播接收器...

    隐式Intent的应用

    隐式Intent是Android系统中的一种重要机制,它用于在应用程序之间建立通信桥梁,使得一个应用可以触发另一个应用的特定操作,而无需明确指定接收方是谁。这种机制极大地增强了Android生态系统的可扩展性和交互性。 ...

    Android中关于Broadcast、Intent 的应用

    在Android系统中,Broadcast(广播)和Intent是两个至关重要的组件,它们构成了应用程序间通信的基础。Broadcast用于在应用程序之间传递消息,而Intent则扮演着触发操作的“信使”角色。理解并熟练运用这两个概念,...

    Android应用:Intent打开另外一个Activity,Intent拨电话,Intent在2个Activity间传递参数

    在Android应用开发中,Intent是一种强大的机制,用于在组件之间进行通信。Intent不仅可以用来启动新的Activity,还可以启动服务、广播接收器等。本教程将详细讲解如何使用Intent来实现特定的功能,包括打开新的...

    Android应用核心Intent

    在Android开发中,Intent是一个至关重要的概念,它充当着应用程序组件间通信的桥梁。Intent不仅用于启动活动(Activity)或服务(Service),还能传递数据、启动广播接收器(BroadcastReceiver)。下面将深入探讨...

    Android通过Intent跳转地图应用(百度地图、高德地图)

    当我们需要在应用程序中调用外部应用,如地图应用,如百度地图或高德地图,Intent是实现这一功能的关键。本篇文章将深入讲解如何使用Intent在Android应用中跳转到这些地图应用,并在用户未安装相应地图应用时提供...

    Android应用源码之Intent_Intent.zip

    在Android开发中,Intent是一个非常核心且至关重要的组件,它扮演着应用程序内部或应用程序之间通信的桥梁角色。Intent主要用于启动活动(Activity)、服务(Service)或者广播接收器(BroadcastReceiver),并传递...

    intent的简单应用

    Intent是Android系统中一个至关重要的概念,它是应用程序之间通信的主要桥梁。Intent允许应用程序启动其他活动(Activity)、服务(Service)或者传递数据。在Android开发中,理解并熟练使用Intent是构建用户界面和...

    android中使用隐式intent完成应用的步骤及核心代码2022优秀文档.pptx

    Android 中使用隐式 Intent 完成应用的步骤及核心代码 Android 中的 Intent 机制是一种在不同组件之间传递请求消息的机制。Intent 可以分为显式 Intent 和隐式 Intent 两种。显式 Intent 是指明确指出了目标组件...

    android中使用显式intent完成应用的步骤及核心代码2022优秀文档.pptx

    "Android中使用显式Intent完成应用的步骤及核心代码" Android中使用显式Intent完成应用的步骤及核心代码是指在Android应用程序中使用显式Intent来实现应用程序之间的交互和跳转。显式Intent是一种明确指出了目标...

    intent应用

    本篇将深入探讨Intent的使用,包括页面间的跳转、数据传递以及简单的Intent应用。 1. 页面跳转: Intent主要用于启动Activity,实现页面之间的跳转。例如,当你点击一个按钮想要打开一个新的Activity时,你可以创建...

    Android应用源码之Intent1_Intent.zip

    在Android开发中,Intent是一个非常核心且至关重要的组件,它扮演着应用程序内部或不同应用程序之间通信的桥梁。Intent1_Intent.zip中的源码应该包含了关于Intent的实例和使用方法,让我们一起深入探讨Intent在...

    android intent 应用实例详解

    Android Intent 是Android应用程序之间通信的重要机制,用于启动其他组件或传递数据。Intent 分为两种类型:显式 Intent 和隐式 Intent。 1. **显式 Intent**: 显式 Intent 是指明确指定要启动的组件(Activity、...

    Android应用源码之Intent.zip

    在Android应用开发中,Intent是一个至关重要的概念,它充当了应用程序组件之间通信的桥梁。Intent不仅用于启动新的活动(Activity)或服务(Service),还能在组件间传递数据。本资料"Android应用源码之Intent.zip...

    Android的Intent实验

    在Android开发中,Intent是一种非常重要的组件,它用于在应用程序的不同组件之间传递消息,实现活动(Activity)、服务(Service)、广播接收器(Broadcast Receiver)以及内容提供者(Content Provider)之间的交互...

    Android中使用Intent获取其他应用程序信息的方法介绍.pdf

    本文主要探讨了如何利用Intent在Android系统中获取并操作其他应用程序的信息。以下是对这些方法的详细解释: 1. 卸载应用程序 使用Intent ACTION_DELETE可以实现卸载已安装的应用程序。首先,构建一个Uri对象,其...

    Intent 与 Intent Filters 实现外部调用

    在Android开发中,Intent和Intent Filters是两个至关重要的概念,它们是应用程序之间通信的主要桥梁,也是实现外部调用的关键机制。下面将详细讲解Intent和Intent Filters的工作原理以及如何使用它们来实现外部调用...

    实验七 使用Intent在Activity间传输数据

    在Android应用开发中,Intent是连接应用程序组件的重要机制,它被用来启动新的活动(Activity)或者传递消息。在“实验七 使用Intent在Activity间传输数据”中,我们将深入理解Intent的工作原理及其在不同Activity间...

    Intent系统调用示例

    - 隐式Intent:不指定具体组件,而是通过Action、Data、Category等属性来描述要执行的操作,其他应用可以注册对应的接收者来响应这个Intent,常用于跨应用通信。 2. **Intent的构造与属性** 创建Intent时,通常...

    隐式Intent

    隐式Intent是Android系统中的一种重要机制,它用于在应用程序之间建立通信桥梁,使得不同的应用组件可以互相调用,实现跨组件交互。隐式Intent不指定具体的接收者,而是通过定义一个行动(Action)、数据(Data)、...

Global site tag (gtag.js) - Google Analytics