`
wangleyiang
  • 浏览: 218695 次
社区版块
存档分类
最新评论

『转』Android Intent常见应用

阅读更多

转自:http://blog.csdn.net/spy19881201/article/details/5770971

 部分代码有待进一步验证

 参考:http://developer.android.com/training/sharing/index.html

 

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);  
Java代码 
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);   
Java代码 
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);  
Java代码 
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);   
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);  
  
要使用这个必须在配置文件中加入  
Java代码 
Uri uri = Uri.parse("tel.xxxxxx");  
Intent it =new Intent(Intent.ACTION_CALL,uri);  
要使用这个必须在配置文件中加入  


发送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( "file://mnt//sdcard//image.jpg" );     
  
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("file://mnt//sdcard//image.jpg");     
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     
  
  


显示指定应用的详细页面

  
Uri uri = Uri.parse("market://details?id=app_id" );    
  
Intent it = new  Intent(Intent.ACTION_VIEW, uri);    
  
startActivity(it);    
分享到:
评论

相关推荐

    Android Intent Filter用法

    常见的类别有CATEGORY_DEFAULT(默认类别,大多数Intent都会包含)、CATEGORYBrowsable(表示可以作为用户浏览的内容)、CATEGORY_LAUNCHER(使应用出现在启动器中)。在<intent-filter>中添加<category android:...

    Android利用Intent启动和关闭Activity

    在Android应用程序开发中,Intent是连接各个组件(如Activity、Service等)的关键桥梁,主要用于启动和关闭Activity。Intent不仅能够启动一个新的Activity,还能在Activity之间传递数据,实现应用内部或应用间的交互...

    Android Intent多种传值方式

    以上就是Android Intent在不同场景下常见的传值方式。在实际开发中,开发者需要根据数据类型和需求选择合适的方法进行数据传递,确保应用的稳定性和性能。通过熟练掌握这些技巧,开发者能够更好地构建Android应用...

    Android应用源码之Intent1_Intent.zip

    Intent1_Intent.zip中的源码应该包含了关于Intent的实例和使用方法,让我们一起深入探讨Intent在Android应用中的作用、类型、创建与传递、以及常见用法。 1. **Intent的作用** Intent的主要功能是启动一个活动...

    android中intent使用示例

    本示例将深入探讨Intent的基本用法和常见应用场景。 首先,Intent分为显式Intent和隐式Intent两种类型。显式Intent通过指定组件的全名(包括包名和类名)来直接启动目标组件,而隐式Intent则是通过设置Action、Data...

    Android程序间Intent跳转分析

    3. **选择本机图片操作**: 使用ACTION_PICK或ACTION_GET_CONTENT Intent,开发者可以让用户从设备图库中选择图片,这在需要上传图片或设置头像的应用场景中非常常见。 4. **利用第三方应用打开文件**: 当你想要使用...

    Android Intent的几种用法全面总结

    以下是Android Intent的几种常见用法的详细解释: 1. 显示网页: 当你想在设备上打开一个网页时,可以通过ACTION_VIEW Intent与系统浏览器交互。例如: ```java Uri uri = Uri.parse("http://www.google.com"); ...

    Android Intent用法大全

    ### Android Intent用法大全 #### 概述 在Android开发中,`Intent`是一个非常重要的概念,它主要用于组件之间的通信,比如启动一个...理解并熟练掌握`Intent`的使用方法对于开发高质量的Android应用至关重要。

    android常用Intent

    以上是Android开发中常见的Intent使用场景,通过这些示例,我们可以看到Intent的灵活性和强大的功能,它能够帮助开发者实现应用程序之间的交互和数据共享。在实际开发过程中,合理利用Intent可以极大地提升应用的...

    Android中Intent和ProgressBar的结合使用

    总的来说,Intent和ProgressBar的结合使用是Android开发中常见的场景,尤其在处理耗时操作时,可以提供良好的用户反馈,提升用户体验。通过理解Intent的原理以及ProgressBar的用法,开发者可以更好地控制应用程序的...

    Android代码-Intent切换.zip

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

    android intent and intent-filters

    在Android应用开发中,Intent是连接应用程序组件的重要机制,它是一种消息传递对象,用于启动其他组件(如Activity、Service、BroadcastReceiver)或者传递数据。Intent-filters则定义了组件能够响应的Intent类型,...

    android intent和intent action大全.doc

    这些示例展示了Intent在Android开发中的常见用途,包括搜索、导航、通信等。理解并熟练运用Intent,对于构建具有完整功能的Android应用至关重要。此外,Intent还有许多其他ACTION,例如`ACTION_PICK`用于选择数据,`...

    Android Button+Intent案例代码包

    这个案例会覆盖基本的布局设计、事件监听和Intent的使用,是理解Android应用开发基础的绝佳实践。 总之,掌握Button和Intent的使用对于Android开发者来说至关重要。它们是构建用户交互和组件通信的基础,通过理解和...

    Android从一个应用跳转到另一个应用

    在Android开发中,应用间的跳转是常见的交互方式,它允许用户在不同的应用程序之间自由切换,实现各种功能的联动。本教程将详细讲解如何在Android应用中实现从一个应用跳转到另一个应用。 首先,我们需要了解...

    隐式Intent

    在描述中提到的"隐式Intent的简单应用"主要涉及两个常见场景:发送文本信息和选择联系人。接下来我们将深入探讨这两个应用场景。 1. 发送文本信息(SMS): 当应用需要发送短信时,可以通过隐式Intent来启动系统的...

    Android官方文档Context&Intent页保存

    在Android应用开发中,`Context`和`Intent`是两个至关重要的概念,它们构成了Android系统的基础框架,并在组件间通信中扮演着核心角色。这里,我们深入探讨一下这两个类的功能和使用。 首先,`Context`可以理解为...

Global site tag (gtag.js) - Google Analytics