zoukankan      html  css  js  c++  java
  • android组件通讯 Intent 系统标准的Activity Action应用

    标准的Activity Actions

    1. ACTION_M AIN 作为一个主要的进入口,而并不期望去接受数据   
    2. ACTION_VIEW 向用户去显示数据   
    3. ACTION_ATTACH_DATA  别用于指定一些数据应该附属于一些其他的地方,例如,图片数据应该附属于联系人   
    4. ACTION_EDIT 访问已给的数据,提供明确的可编辑   
    5. ACTION_PICK 从数据中选择一个子项目,并返回你所选中的项目   
    6. ACTION_CHOOSER 显示一个activity选择器,允许用户在进程之前选择他们想要的   
    7. ACTION_GET_CONTENT 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)   
    8. ACTION_DIAL 拨打一个指定的号码,显示一个带有号码的用户界面,允许用户去启动呼叫   
    9. ACTION_CALL 根据指定的数据执行一次呼叫   
    10.  (ACTION_CALL在应用中启动一次呼叫有缺陷,多数应用ACTION_DIAL,ACTION_CALL不能用在紧急呼叫上,紧急呼叫可以用ACTION_DIAL来实现)   
    11. ACTION_SEND 传递数据,被传送的数据没有指定,接收的action请求用户发数据   
    12. ACTION_SENDTO 发送一跳信息到指定的某人   
    13. ACTION_ANSWER 处理一个打进电话呼叫   
    14. ACTION_INSERT 插入一条空项目到已给的容器   
    15. ACTION_DELETE 从容器中删除已给的数据   
    16. ACTION_RUN 运行数据,无论怎么   
    17. ACTION_SYNC 同步执行一个数据   
    18. ACTION_PICK_ACTIVITY 为以为的Intent选择一个Activity,返回别选中的类   
    19. ACTION_SEARCH 执行一次搜索   
    20. ACTION_WEB_SEARCH 执行一次web搜索   
    21. ACTION_FACTORY_TEST 工场测试的主要进入点,   

    标准的广播Actions   

    1. ACTION_TIME_TICK  当前时间改变,每分钟都发送,不能通过组件声明来接收,只有通过Context.registerReceiver()方法来注册   
    2. ACTION_TIME_CHANGED 时间被设置   
    3. ACTION_TIMEZONE_CHANGED 时间区改变   
    4. ACTION_BOOT_COMPLETED 系统完成启动后,一次广播   
    5. ACTION_PACKAGE_ADDED 一个新应用包已经安装在设备上,数据包括包名(最新安装的包程序不能接收到这个广播)   
    6. ACTION_PACKAGE_CHANGED 一个已存在的应用程序包已经改变,包括包名   
    7. ACTION_PACKAGE_REMOVED 一个已存在的应用程序包已经从设备上移除,包括包名(正在被安装的包程序不能接收到这个广播)   
    8. ACTION_PACKAGE_RESTARTED 用户重新开始一个包,包的所有进程将被杀死,所有与其联系的运行时间状态应该被移除,包括包名(重新开始包程序不能接收到这个广播)   
    9. ACTION_PACKAGE_DATA_CLEARED 用户已经清楚一个包的数据,包括包名(清除包程序不能接收到这个广播)   
    10. ACTION_BATTERY_CHANGED 电池的充电状态、电荷级别改变,不能通过组建声明接收这个广播,只有通过Context.registerReceiver()注册   
    11. 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);
    }

    @Override
    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:
    data
    = "content://contacts/people/1";
    uri
    = Uri.parse(data);
    intent.setAction(Intent.ACTION_EDIT);
    intent.setData(uri);
    startActivity(intent);
    break;
    // 显示拨打电话界面
    case 2:
    data
    = "tel:13800138000";
    uri
    = Uri.parse(data);
    intent.setAction(Intent.ACTION_DIAL);
    intent.setData(uri);
    startActivity(intent);
    break;
    // 直接打电话
    case 3:
    data
    = "tel:13800138000";
    uri
    = Uri.parse(data);
    intent.setAction(Intent.ACTION_CALL);
    intent.setData(uri);
    startActivity(intent);
    break;
    // 访问浏览器
    case 4:
    data
    = "http://www.google.com";
    uri
    = Uri.parse(data);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(uri);
    startActivity(intent);
    break;
    // 访问地图
    case 5:
    data
    = "geo:39.92,116.46";
    uri
    = Uri.parse(data);
    intent
    = new Intent(Intent.ACTION_VIEW,uri);
    startActivity(intent);
    break;
    default:
    break;
    }
    }
    }

    布局文件

    /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

    代码
    <?xml version="1.0" encoding="utf-8"?>
    <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>

  • 相关阅读:
    Thymeleaf
    JdbcTemplate
    submit提交判断
    C++经典排序算法的理解:冒泡排序和选择排序
    求二进制中1的个数
    记录一次读取hdfs文件时出现的问题java.net.ConnectException: Connection refused
    linux服务器间配置ssh免密连接
    psycopg2模块安装问题
    sklearn.tree.DecisionTreeClassifier 详细说明
    sklearn.neighbors.NNeighborsClassifier 详细说明
  • 原文地址:https://www.cnblogs.com/linzheng/p/1939740.html
Copyright © 2011-2022 走看看