标準的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