生活随笔
收集整理的這篇文章主要介紹了
android组件通讯 Intent- 系统标准的Activity Action应用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
標(biāo)準(zhǔn)的Activity Actions
?
ACTION_M AIN 作為一個主要的進入口,而并不期望去接受數(shù)據(jù) ACTION_VIEW 向用戶去顯示數(shù)據(jù) ACTION_ATTACH_DATA 別用于指定一些數(shù)據(jù)應(yīng)該附屬于一些其他的地方,例如,圖片數(shù)據(jù)應(yīng)該附屬于聯(lián)系人 ACTION_EDIT 訪問已給的數(shù)據(jù),提供明確的可編輯 ACTION_PICK 從數(shù)據(jù)中選擇一個子項目,并返回你所選中的項目 ACTION_CHOOSER 顯示一個activity選擇器,允許用戶在進程之前選擇他們想要的 ACTION_GET_CONTENT 允許用戶選擇特殊種類的數(shù)據(jù),并返回(特殊種類的數(shù)據(jù):照一張相片或錄一段音) ACTION_DIAL 撥打一個指定的號碼,顯示一個帶有號碼的用戶界面,允許用戶去啟動呼叫 ACTION_CALL 根據(jù)指定的數(shù)據(jù)執(zhí)行一次呼叫 (ACTION_CALL在應(yīng)用中啟動一次呼叫有缺陷,多數(shù)應(yīng)用ACTION_DIAL,ACTION_CALL不能用在緊急呼叫上,緊急呼叫可以用ACTION_DIAL來實現(xiàn)) ACTION_SEND 傳遞數(shù)據(jù),被傳送的數(shù)據(jù)沒有指定,接收的action請求用戶發(fā)數(shù)據(jù) ACTION_SENDTO 發(fā)送一跳信息到指定的某人 ACTION_ANSWER 處理一個打進電話呼叫 ACTION_INSERT 插入一條空項目到已給的容器 ACTION_DELETE 從容器中刪除已給的數(shù)據(jù) ACTION_RUN 運行數(shù)據(jù),無論怎么 ACTION_SYNC 同步執(zhí)行一個數(shù)據(jù) ACTION_PICK_ACTIVITY 為以為的Intent選擇一個Activity,返回別選中的類 ACTION_SEARCH 執(zhí)行一次搜索 ACTION_WEB_SEARCH 執(zhí)行一次web搜索 ACTION_FACTORY_TEST 工場測試的主要進入點, 標(biāo)準(zhǔn)的廣播Actions
ACTION_TIME_TICK 當(dāng)前時間改變,每分鐘都發(fā)送,不能通過組件聲明來接收,只有通過Context.registerReceiver()方法來注冊 ACTION_TIME_CHANGED 時間被設(shè)置 ACTION_TIMEZONE_CHANGED 時間區(qū)改變 ACTION_BOOT_COMPLETED 系統(tǒng)完成啟動后,一次廣播 ACTION_PACKAGE_ADDED 一個新應(yīng)用包已經(jīng)安裝在設(shè)備上,數(shù)據(jù)包括包名(最新安裝的包程序不能接收到這個廣播) ACTION_PACKAGE_CHANGED 一個已存在的應(yīng)用程序包已經(jīng)改變,包括包名 ACTION_PACKAGE_REMOVED 一個已存在的應(yīng)用程序包已經(jīng)從設(shè)備上移除,包括包名(正在被安裝的包程序不能接收到這個廣播) ACTION_PACKAGE_RESTARTED 用戶重新開始一個包,包的所有進程將被殺死,所有與其聯(lián)系的運行時間狀態(tài)應(yīng)該被移除,包括包名(重新開始包程序不能接收到這個廣播) ACTION_PACKAGE_DATA_CLEARED 用戶已經(jīng)清楚一個包的數(shù)據(jù),包括包名(清除包程序不能接收到這個廣播) ACTION_BATTERY_CHANGED 電池的充電狀態(tài)、電荷級別改變,不能通過組建聲明接收這個廣播,只有通過Context.registerReceiver()注冊 ACTION_UID_REMOVED 一個用戶ID已經(jīng)從系統(tǒng)中移除 ?
一、打電話、訪問瀏覽器地圖的Activity Action應(yīng)用
程序文件
/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); ?????????//?菜單項數(shù)組 ?????????String[]?menus?=?{?"查看電話信息",?"編輯電話信息",?"顯示撥打電話界面","直接打電話","訪問瀏覽器","訪問地圖"}; ?????????//?將菜單項數(shù)組設(shè)置為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>? ?
轉(zhuǎn)載于:https://blog.51cto.com/linzheng/1080662
總結(jié)
以上是生活随笔為你收集整理的android组件通讯 Intent- 系统标准的Activity Action应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。