天天看点

android组件通讯 Intent- 系统标准的Activity Action应用

标准的Activity Actions

ACTION_M AIN 作为一个主要的进入口,而并不期望去接受数据

ACTION_VIEW 向用户去显示数据

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

ACTION_EDIT 访问已给的数据,提供明确的可编辑

ACTION_PICK 从数据中选择一个子项目,并返回你所选中的项目

ACTION_CHOOSER 显示一个activity选择器,允许用户在进程之前选择他们想要的

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

ACTION_DIAL 拨打一个指定的号码,显示一个带有号码的用户界面,允许用户去启动呼叫

ACTION_CALL 根据指定的数据执行一次呼叫

(ACTION_CALL在应用中启动一次呼叫有缺陷,多数应用ACTION_DIAL,ACTION_CALL不能用在紧急呼叫上,紧急呼叫可以用ACTION_DIAL来实现)

ACTION_SEND 传递数据,被传送的数据没有指定,接收的action请求用户发数据

ACTION_SENDTO 发送一跳信息到指定的某人

ACTION_ANSWER 处理一个打进电话呼叫

ACTION_INSERT 插入一条空项目到已给的容器

ACTION_DELETE 从容器中删除已给的数据

ACTION_RUN 运行数据,无论怎么

ACTION_SYNC 同步执行一个数据

ACTION_PICK_ACTIVITY 为以为的Intent选择一个Activity,返回别选中的类

ACTION_SEARCH 执行一次搜索

ACTION_WEB_SEARCH 执行一次web搜索

ACTION_FACTORY_TEST 工场测试的主要进入点,

标准的广播Actions

ACTION_TIME_TICK 当前时间改变,每分钟都发送,不能通过组件声明来接收,只有通过Context.registerReceiver()方法来注册

ACTION_TIME_CHANGED 时间被设置

ACTION_TIMEZONE_CHANGED 时间区改变

ACTION_BOOT_COMPLETED 系统完成启动后,一次广播

ACTION_PACKAGE_ADDED 一个新应用包已经安装在设备上,数据包括包名(最新安装的包程序不能接收到这个广播)

ACTION_PACKAGE_CHANGED 一个已存在的应用程序包已经改变,包括包名

ACTION_PACKAGE_REMOVED 一个已存在的应用程序包已经从设备上移除,包括包名(正在被安装的包程序不能接收到这个广播)

ACTION_PACKAGE_RESTARTED 用户重新开始一个包,包的所有进程将被杀死,所有与其联系的运行时间状态应该被移除,包括包名(重新开始包程序不能接收到这个广播)

ACTION_PACKAGE_DATA_CLEARED 用户已经清楚一个包的数据,包括包名(清除包程序不能接收到这个广播)

ACTION_BATTERY_CHANGED 电池的充电状态、电荷级别改变,不能通过组建声明接收这个广播,只有通过Context.registerReceiver()注册

ACTION_UID_REMOVED 一个用户ID已经从系统中移除

一、打电话、访问浏览器地图的Activity Action应用

程序文件

/Chapter06_Intent_SystemAction/src/com/amaker/ch06/app/MainActivity.java

代码  

package com.amaker.ch06.app;  

import android.app.ListActivity;  

import android.content.Intent;  

import android.net.Uri;  

import android.os.Bundle;  

import android.view.View;  

import android.widget.ArrayAdapter;  

import android.widget.ListView;  

public class MainActivity extends ListActivity {  

    @Override  

    public void onCreate(Bundle savedInstanceState) {  

        super.onCreate(savedInstanceState);  

        // 菜单项数组  

        String[] menus = { "查看电话信息", "编辑电话信息", "显示拨打电话界面","直接打电话","访问浏览器","访问地图"};  

        // 将菜单项数组设置为ListView的列表项展示  

        setListAdapter(new ArrayAdapter<String>(this,  

                android.R.layout.simple_list_item_1, menus));  

        getListView().setTextFilterEnabled(true);  

    }  

    protected void onListItemClick(ListView l, View v, int position, long id) {  

        Intent intent = new Intent();  

        Uri uri ;  

        String data;  

        switch (position) {  

        // 查看_id 为1的用户电话信息  

        case 0:  

            data = "content://contacts/people/1";  

            uri = Uri.parse(data);  

            intent.setAction(Intent.ACTION_VIEW);  

            intent.setData(uri);  

            startActivity(intent);  

            break;  

        // 编辑_id 为1的用户电话信息  

        case 1:  

            intent.setAction(Intent.ACTION_EDIT);  

        // 显示拨打电话界面  

        case 2:  

            data = "tel:13800138000";  

            intent.setAction(Intent.ACTION_DIAL);  

        // 直接打电话  

        case 3:  

            intent.setAction(Intent.ACTION_CALL);  

        // 访问浏览器  

        case 4:  

            data = "http://www.google.com";  

        // 访问地图  

        case 5:  

            data = "geo:39.92,116.46";  

            intent = new Intent(Intent.ACTION_VIEW,uri);  

        default:  

        }  

布局文件

/Chapter06_Intent_SystemAction/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:orientation="vertical" android:layout_width="fill_parent" 

    android:layout_height="fill_parent"> 

<Button android:text="@+id/Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 

</LinearLayout> 

清单文件

/Chapter06_Intent_SystemAction/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 

      package="com.amaker.ch06.app" 

      android:versionCode="1" 

      android:versionName="1.0"> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 

        <activity android:name=".MainActivity" 

                  android:label="@string/app_name"> 

            <intent-filter> 

                <action android:name="android.intent.action.MAIN" /> 

                <category android:name="android.intent.category.LAUNCHER" /> 

            </intent-filter> 

        </activity> 

    </application> 

    <uses-sdk android:minSdkVersion="3" /> 

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 

</manifest> 

本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080662

继续阅读