`

Android开发之Intent.Action

 
阅读更多

 

http://www.cnblogs.com/hanyonglu/archive/2012/03/26/2417278.html

本文介绍Android中Intent的各种常见作用。

 

1 Intent.ACTION_MAIN

String: android.intent.action.MAIN

标识Activity为一个程序的开始。比较常用。

Input:nothing

Output:nothing 

 

<activity android:name=".Main" android:label="@string/app_name">   
<intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity> 

 

2 Intent.Action_CALL

Stirng: android.intent.action.CALL

呼叫指定的电话号码。

Input:电话号码。数据格式为:tel:+phone number 

Output:Nothing 

 

Intent intent=new Intent(); 

intent.setAction(Intent.ACTION_CALL);   
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);

 

3 Intent.Action.DIAL

String: action.intent.action.DIAL

调用拨号面板


Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL);   //android.intent.action.DIAL
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent); 


Input:电话号码。数据格式为:tel:+phone number 

Output:Nothing

说明:打开Android的拨号UI。如果没有设置数据,则打开一个空的UI,如果设置数据,action.DIAL则通过调用getData()获取电话号码。

但设置电话号码的数据格式为 tel:+phone number. 

 

4 Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS

列出所有的应用。

Input:Nothing.

Output:Nothing.

 

5 Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER

处理呼入的电话。

Input:Nothing.

Output:Nothing.

 

6 Intent.ACTION_ATTACH_DATA

String: android.action.ATTCH_DATA

别用于指定一些数据应该附属于一些其他的地方,例如,图片数据应该附属于联系人

Input: Data

Output:nothing

 

7 Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT

显示Dug报告。

Input:nothing

output:nothing

 

8 Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.

相当于用户按下“拨号”键。经测试显示的是“通话记录”

Input:nothing

Output:nothing

 

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);

 

9 Intent.ACTION_CHOOSER

String: android.intent.action.CHOOSER

显示一个activity选择器,允许用户在进程之前选择他们想要的,与之对应的是Intent.ACTION_GET_CONTENT.

 

10. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT

允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音) 

Input: Type

Output:URI

 

int requestCode = 1001;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
intent.setType("image/*"); // 查看类型,如果是其他类型,比如视频则替换成 video/*,或 */*
Intent wrapperIntent = Intent.createChooser(intent, null);

startActivityForResult(wrapperIntent, requestCode);  


11 Intent.ACTION_VIEW

String android.intent.action.VIEW

用于显示用户的数据。

比较通用,会根据用户的数据类型打开相应的Activity。

比如 tel:13400010001打开拨号程序,http://www.g.cn则会打开浏览器等。

 

Uri uri = Uri.parse("http://www.google.com"); //浏览器 
Uri uri =Uri.parse("tel:1232333"); //拨号程序 
Uri uri=Uri.parse("geo:39.899533,116.036476"); //打开地图定位 
Intent it = new Intent(Intent.ACTION_VIEW,uri); 
startActivity(it); 

//播放视频 
Intent intent = new Intent(Intent.ACTION_VIEW); 
Uri uri = Uri.parse("file:///sdcard/media.mp4"); 
intent.setDataAndType(uri, "video/*"); 
startActivity(intent);

//调用发送短信的程序 
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "信息内容..."); 
it.setType("vnd.android-dir/mms-sms"); 
startActivity(it);

 

12 Intent.ACTION_SENDTO 

String: android.intent.action.SENDTO 
说明:发送短信息

 

//发送短信息 
Uri uri = Uri.parse("smsto:13200100001"); 
Intent it = new Intent(Intent.ACTION_SENDTO, uri); 
it.putExtra("sms_body", "信息内容..."); 
startActivity(it); 

 

复制代码
//发送彩信,设备会提示选择合适的程序发送 
Uri uri = Uri.parse("content://media/external/images/media/23"); 
//设备中的资源(图像或其他资源) 
Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra("sms_body", "内容"); 
intent.putExtra(Intent.EXTRA_STREAM, uri); 
intent.setType("image/png"); 
startActivity(it);
复制代码


复制代码
 //Email 
Intent intent=new Intent(Intent.ACTION_SEND); 
String[] tos={"android1@163.com"}; 
String[] ccs={"you@yahoo.com"}; 
intent.putExtra(Intent.EXTRA_EMAIL, tos); 
intent.putExtra(Intent.EXTRA_CC, ccs);
 intent.putExtra(Intent.EXTRA_TEXT, "The email body text"); 
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text"); 
intent.setType("message/rfc822"); 
startActivity(Intent.createChooser(intent, "Choose Email Client"));
复制代码

 

13 Intent.ACTION_GET_CONTENT

 

//选择图片 requestCode 返回的标识
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
intent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);  


//添加音频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);  



复制代码
 //拍摄视频 
int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.duration", 60);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
复制代码

 

//视频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);  


//录音
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr";
intent.setClassName("com.android.soundrecorder",
"com.android.soundrecorder.SoundRecorder");
((Activity) context).startActivityForResult(intent, requestCode);  


//拍照 REQUEST_CODE_TAKE_PICTURE 为返回的标识
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";
intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace");
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);  

 

 

分享到:
评论

相关推荐

    android.intent.action.TIME_TICK

    3. 注册IntentFilter:为IntentFilter添加对应的ACTION,如"android.intent.action.TIME_TICK"、"android.intent.action.SCREEN_ON"和"android.intent.action.BATTERY_CHANGED"。 4. 不再需要时,记得在合适的位置...

    android Action call 拨打电话 Intent.ACTION.CALL

    在Android开发中,Intent是一个非常重要的组件,它用于在应用程序的不同组件之间传递消息,执行特定的操作,如启动活动(Activity)、启动服务(Service)等。当我们想要从应用中拨打电话时,就需要用到Intent ...

    Intent.action_大全

    在Android开发中,`Intent`作为组件间通信的重要机制之一,其通过携带特定的信息在不同组件之间进行传递,从而实现组件间的交互与通信。`Intent`有两种类型:显式Intent和隐式Intent。其中隐式Intent通过指定`action...

    android 常用的intent action整理

    在Android开发中,Intent作为一个重要的组成部分,扮演着连接各个组件的角色。它不仅能够实现组件间的简单数据传递,还能够执行更为复杂的功能,比如调用拨号功能、处理接收短信等。通过设置Intent的不同属性,...

    android各组件详解- Intent.

    标题与描述均指向了“Android各组件详解——Intent”,这一主题深入探讨了Android开发中至关重要的Intent组件。本文将从多个角度解析Intent的功能、应用场景及其内部结构,为开发者提供全面的理解。 ### Intent概述...

    Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面.

    Intent intent = new Intent("android.intent.action.DIAL"); intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity"); startActivity(intent); ``` 通话记录界面 要跳转到通话...

    Android利用Intent.ACTION_SEND进行分享

    在Android开发中,Intent是应用之间通信的重要工具,它允许我们启动其他应用的活动或服务。当我们想要在应用中实现分享功能时,可以利用Intent.ACTION_SEND这一动作来完成。ACTION_SEND Intent使得用户能够将数据...

    用Intent.ACTION_SEND进行分享

    在Android开发中,Intent是应用间通信的重要工具,它用于启动其他Activity或Service,传递数据,实现组件间的交互。Intent.ACTION_SEND是Intent的一个特定动作,用于实现应用中的内容分享功能。当你点击一个“分享”...

    intent_action大全

    根据提供的文件信息,我们可以总结出一系列关于Android应用开发中的Intent操作相关知识点。这些知识点主要涉及如何使用Intents来启动各种类型的活动(如网页浏览、地图导航、拨打电话、发送短信等)。下面将对每一个...

    Android应用源码之Intent.zip

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

    Android使用Intent.ACTION_SEND分享图片和文字内容的示例代码

    Android 使用 Intent.ACTION_SEND 分享图片和文字内容的示例代码详解 ...同时,掌握 Intent.ACTION_SEND 也可以帮助我们更好地理解 Android 操作系统的工作机制,从而更好地开发 Android 应用程序。

    安卓Android源码——Intent.rar

    总之,“安卓Android源码——Intent.rar”这个资源对于想要深入了解Android开发的开发者来说非常有价值,它涵盖了Intent的基本概念、工作原理和实际应用,结合源码分析可以提升开发者对Android系统级组件的理解。

    Android广播接实现监听电话状态(电话的状态,拦截)

    &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt; &lt;/intent-filter&gt; ``` 在实现监听电话状态的功能时,开发者应该注意遵守用户隐私和安全的法律法规,保证应用行为的合法性。在某些国家和地区...

    android Intent实例

    在Android开发中,`Intent`扮演着极其重要的角色,它是应用程序内部以及不同应用程序之间通信的主要方式之一。通过`Intent`,开发者能够实现各种功能,比如打开网页、启动地图应用、拨打电话、发送电子邮件等。本文...

    Android中获取系统图片示例

    在Android开发中,有时我们需要获取用户的系统图片,例如在创建相册、编辑个人资料或分享功能中。本文将详细介绍如何通过两种方法实现这一目标:Intent.ACTION_GET_CONTENT 和 MediaStore。 首先,我们来看Intent....

    Android 常用的Intent的URI及示例

    在Android开发中,Intent作为应用间通信的核心机制之一,扮演着至关重要的角色。它不仅能够启动应用程序组件(如Activity、Service或BroadcastReceiver),还能在组件之间传递数据。Intent中的URI(Uniform Resource...

    android各种文件的intent

    在Android开发中,`Intent`是一种消息对象,它允许您启动Activity、Service或者发送Broadcast等。简单来说,Intent是应用程序组件之间进行交互的一种方式。它可以携带少量数据,并指定一个要执行的动作(例如查看...

    android用于打开各种文件的intent.docx

    在Android开发过程中,我们经常需要使用`Intent`来启动应用内的特定功能或者跳转到其他应用来处理某些文件类型(如PDF、PPT、Word文档等)。本文将详细介绍如何创建不同类型的`Intent`来打开或处理各种文件。 #### ...

Global site tag (gtag.js) - Google Analytics