標準的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); ?????} ????? ?????@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>? ?
轉載于:https://blog.51cto.com/linzheng/1080662
總結
以上是生活随笔為你收集整理的android组件通讯 Intent- 系统标准的Activity Action应用的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。