Android Intent Action 大全

1.Intent的用法:android

(1)Action跳轉web

一、 使用Action跳轉,當程序AndroidManifest.xml中某一個 Activity的IntentFilter定義了包含Action,若是剛好與目標Action匹配,且其IntentFilter中沒有定義其它的Type或Category過濾條件,那麼就正好匹配了。若是手機中有兩個以上的Action程序匹配,那麼就會彈出一個對話可框來提示說明。例如打開一個網址,彈出可選對話框:瀏覽器



Action 的值在Android中有不少預約義,若是想直接轉到本身定義的Intent接收者,能夠在接收者的IntentFilter 中加入一個自定義的Action值(同時要設定 Category值爲"android.intent.category.DEFAULT"),在你的Intent中設定該值爲Intent的 Action就直接能跳轉到你本身的Intent接收者中,由於這個Action在系統中是惟一的。安全

二、 data/type,能夠用Uri 來作爲data,好比Uri uri = Uri.parse(「http://blog.csdn.net/sunboy_2050); Intent i = new Intent(Intent.ACTION_VIEW, uri); 手機的Intent分發過程當中,會根據「http://blog.csdn.net/sunboy_2050」 的scheme判斷出數據類型type。手機中安裝的全部Brower都能匹配它,在Brower的Manifest.xml中的IntenFilter中首先有ACTION_VIEW 的Action能處理http的type網絡

三、 Category分類,通常不要去在Intent中設置它,若是你寫Intent的接收者就在Manifest.xml的Activity的 IntentFilter中包含android.category.DEFAULT,這樣全部不設置 Category(Intent.addCategory(String c);)的Intent都會與這個Category匹配。app

4,extras 附加信息,是其它全部附加信息的集合。使用extras能夠爲組件提供擴展信息,好比,若是要執行「發送電子郵件」這個動做,能夠將電子郵件的標題、正文等保存在extras裏,傳給電子郵件發送組件。ide


(2)用類名跳轉單元測試

Intent負責對應用中一次操做的動做、動做涉及的數據、附加數據進行描述,Android則根據此Intent的描述, 負責找到對應的組件,將 Intent傳遞給調用的組件,並完成組件的調用。Intent在這裏起着實現調用者與被調用者之間的解耦做用。Intent傳遞過程當中,要找 到目標消費者(另外一個Activity,IntentReceiver,Service),也就是Intent的響應者。測試

Intent intent = new Intent();
intent.setClass(context, targetActivy.
class); // 或者直接用 Intent intent = new Intent(context, targetActivity.class);
ui

startActivity(intent);

不過注意用類名跳轉,須要在AndroidManifest.xml中申明activity

<activity android:name="targetActivity"></activity>



2. 幾種Intent的用法

android 中intent是常常要用到的。不論是頁面牽轉,仍是傳遞數據,或是調用外部程序,系統功能都要用到intent,下面是一些經常使用intent示例:

1.從google搜索內容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);

2.瀏覽網頁
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);

3.顯示地圖
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);

4.路徑規劃
Uri uri = Uri.parse("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);

5.撥打電話
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);

6.調用發短信的程序
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);

7.發送短信
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
String body="this is sms demo";
Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);

8.發送彩信
Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append("file://");
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mmsto", number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity(intent);

9.發送Email
Uri uri = Uri.parse("mailto:xxx@abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me@abc.com"};
String[] ccs={"you@abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Email Client"));

Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));

10.播放多媒體
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

11.uninstall apk
Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);

12.install apk
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

13. 打開照相機

<1>Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
this.sendBroadcast(i);

<2>long dateTaken = System.currentTimeMillis();
String name = createName(dateTaken) + ".jpg";
fileName = folder + name;
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, fileName);
values.put("_data", fileName);
values.put(Images.Media.PICASA_ID, fileName);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DESCRIPTION, fileName);
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
Uri photoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

Intent inttPhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(inttPhoto, 10);

14.從gallery選取圖片
Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);

15. 打開錄音機
Intent mi = new Intent(Media.RECORD_SOUND_ACTION);
startActivity(mi);

16.顯示應用詳細列表
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar

剛纔找app id未果,結果發現用package name也能夠
Uri uri = Uri.parse("market://details?id=<packagename>");
這個簡單多了

17尋找應用
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application

18打開聯繫人列表
<1>
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("vnd.android.cursor.item/phone");
startActivityForResult(i, REQUEST_TEXT);

<2>
Uri uri = Uri.parse("content://contacts/people");
Intent it = new Intent(Intent.ACTION_PICK, uri);
startActivityForResult(it, REQUEST_TEXT);

19 打開另外一程序
Intent i = new Intent();
ComponentName cn = new ComponentName("com.yellowbook.android2",
"com.yellowbook.android2.AndroidSearch");
i.setComponent(cn);
i.setAction("android.intent.action.MAIN");
startActivityForResult(i, RESULT_OK);


20.調用系統編輯添加聯繫人(高版本SDK有效):
Intent it = newIntent(Intent.ACTION_INSERT_OR_EDIT);
it.setType("vnd.android.cursor.item/contact");
//it.setType(Contacts.CONTENT_ITEM_TYPE);
it.putExtra("name","myName");
it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, "organization");
it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,"email");
it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,"homePhone");
it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
"mobilePhone");
it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
"workPhone");
it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,"title");
startActivity(it);

21.調用系統編輯添加聯繫人(全有效):
Intent intent = newIntent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.NAME, "My Name");
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
intent.putExtra(Contacts.Intents.Insert.EMAIL, "com@com.com");
intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);
startActivity(intent);

intent action大全:

  • android.intent.action.ALL_APPS

  • android.intent.action.ANSWER

  • android.intent.action.ATTACH_DATA

  • android.intent.action.BUG_REPORT

  • android.intent.action.CALL

  • android.intent.action.CALL_BUTTON

  • android.intent.action.CHOOSER

  • android.intent.action.CREATE_LIVE_FOLDER

  • android.intent.action.CREATE_SHORTCUT

  • android.intent.action.DELETE

  • android.intent.action.DIAL

  • android.intent.action.EDIT

  • android.intent.action.GET_CONTENT

  • android.intent.action.INSERT

  • android.intent.action.INSERT_OR_EDIT

  • android.intent.action.MAIN

  • android.intent.action.MEDIA_SEARCH

  • android.intent.action.PICK

  • android.intent.action.PICK_ACTIVITY

  • android.intent.action.RINGTONE_PICKER

  • android.intent.action.RUN

  • android.intent.action.SEARCH

  • android.intent.action.SEARCH_LONG_PRESS

  • android.intent.action.SEND

  • android.intent.action.SENDTO

  • android.intent.action.SET_WALLPAPER

  • android.intent.action.SYNC

  • android.intent.action.SYSTEM_TUTORIAL

  • android.intent.action.VIEW

  • android.intent.action.VOICE_COMMAND

  • android.intent.action.WEB_SEARCH

  • android.net.wifi.PICK_WIFI_NETWORK

  • android.settings.AIRPLANE_MODE_SETTINGS

  • android.settings.APN_SETTINGS

  • android.settings.APPLICATION_DEVELOPMENT_SETTINGS

  • android.settings.APPLICATION_SETTINGS

  • android.settings.BLUETOOTH_SETTINGS

  • android.settings.DATA_ROAMING_SETTINGS

  • android.settings.DATE_SETTINGS

  • android.settings.DISPLAY_SETTINGS

  • android.settings.INPUT_METHOD_SETTINGS

  • android.settings.INTERNAL_STORAGE_SETTINGS

  • android.settings.LOCALE_SETTINGS

  • android.settings.LOCATION_SOURCE_SETTINGS

  • android.settings.MANAGE_APPLICATIONS_SETTINGS

  • android.settings.MEMORY_CARD_SETTINGS

  • android.settings.NETWORK_OPERATOR_SETTINGS

  • android.settings.QUICK_LAUNCH_SETTINGS

  • android.settings.SECURITY_SETTINGS

  • android.settings.SETTINGS

  • android.settings.SOUND_SETTINGS

  • android.settings.SYNC_SETTINGS

  • android.settings.USER_DICTIONARY_SETTINGS

  • android.settings.WIFI_IP_SETTINGS

  • android.settings.WIFI_SETTINGS

  • android.settings.WIRELESS_SETTINGS


附錄:

String

"android.intent.action.ADD_SHORTCUT"

動做:在系統中添加一個快捷方式。.

String

"android.intent.action.ALL_APPS"

動做:列舉全部可用的應用。

String

"android.intent.action.ANSWER"

動做:處理撥入的電話。

String

"android.intent.action.BUG_REPORT"

動做:顯示 activity 報告錯誤。

String

"android.intent.action.CALL"

動做:撥打電話,被呼叫的聯繫人在數據中指定。

String

"android.intent.action.CLEAR_CREDENTIALS"

動做:清除登錄憑證 (credential)。

String

"android.intent.action.VIEW"

動做:和 VIEW_ACTION 相同,是在數據上執行的標準動做。

String

"android.intent.action.DELETE"

動做:從容器中刪除給定的數據。

String

"android.intent.action.DIAL"

動做:撥打數據中指定的電話號碼。

String

"android.intent.action.EDIT"

動做:爲制定的數據顯示可編輯界面。

String

"android.intent.action.EMERGENCY_DIAL"

動做:撥打緊急電話號碼。

String

"android.intent.action.LOGIN"

動做:獲取登陸憑證。

String

"android.intent.action.MAIN"

動做:做爲主入口點啓動,不須要數據。

String

"android.intent.action.PICK"

動做:從數據中選擇一個項目item,將被選中的項目返回。

String

"android.intent.action.PICK_ACTIVITY"

動做:選擇一個activity,返回被選擇的activity的類名

String

"android.intent.action.RUN"

動做:運行數據(指定的應用),不管它(應用)是什麼。

String

"android.intent.action.SENDTO"

動做:向 data 指定的接收者發送一個消息。

String

"android.intent.action.GET_CONTENT"

動做:讓用戶選擇數據並返回。

String

"android.intent.action.INSERT"

動做:在容器中插入一個空項 (item)。

String

"android.intent.action.SETTINGS"

動做:顯示系統設置。輸入:無。

String

"android.intent.action.VIEW"

動做:向用戶顯示數據。

String

"android.intent.action.WALLPAPER_SETTINGS"

動做:顯示選擇牆紙的設置界面。輸入:無。

String

"android.intent.action.WEB_SEARCH"

動做:執行 web 搜索。

String

"android.intent.action.SYNC"

動做:執行數據同步。

String

"android.intent.action.SERVICE_STATE"

廣播:電話服務的狀態已經改變。

String

"android.intent.action.TIMEZONE_CHANGED"

廣播:時區已經改變。

String

"android.intent.action.TIME_SET"

廣播:時間已經改變(從新設置)。

String

"android.intent.action.TIME_TICK"

廣播:當前時間已經變化(正常的時間流逝)。

String

"android.intent.action.UMS_CONNECTED"

廣播:設備進入 USB 大容量存儲模式。

String

"android.intent.action.UMS_DISCONNECTED"

廣播:設備從 USB 大容量存儲模式退出。

String

"android.intent.action.WALLPAPER_CHANGED"

廣播:系統的牆紙已經改變。

String

"android.intent.action.XMPP_CONNECTED"

廣播:XMPP 鏈接已經被創建。

String

"android.intent.action.XMPP_DI

廣播:XMPP 鏈接已經被斷開。

String

"android.intent.action.SIG_STR"

廣播:電話的信號強度已經改變。

String

"android.intent.action.BATTERY_CHANGED"

廣播:充電狀態,或者電池的電量發生變化。

String

"android.intent.action.BOOT_COMPLETED"

廣播:在系統啓動後,這個動做被廣播一次(只有一次)

String

"android.intent.action.DATA_ACTIVITY"

廣播:電話的數據活動(data activity)狀態已經改變

String

"android.intent.action.DATA_STATE"

廣播:電話的數據鏈接狀態已經改變。

String

"android.intent.action.DATE_CHANGED"

廣播:日期被改變。

String

"android.server.checkin.FOTA_CANCEL"

廣播:取消全部被掛起的 (pending) 更新下載。

String

"android.server.checkin.FOTA_INSTALL"

廣播:更新已經被確認,立刻就要開始安裝。

String

"android.server.checkin.FOTA_READY"

廣播:更新已經被下載,能夠開始安裝。

String

"android.server.checkin.FOTA_RESTART"

廣播:恢復已經中止的更新下載。

String

"android.server.checkin.FOTA_UPDATE"

廣播:經過 OTA 下載並安裝操做系統更新。

String

"android.intent.action.MEDIABUTTON"

廣播:用戶按下了「Media Button」。

String

"android.intent.action.MEDIA_BAD_REMOVAL"

廣播:擴展卡從SD卡插槽拔出,可是掛載點還沒unmount。

String

"android.intent.action.MEDIA_EJECT"

廣播:用戶想要移除擴展介質(拔掉擴展卡)。

String

"android.intent.action.MEDIA_MOUNTED"

廣播:擴展介質被插入,並且已經被掛載。

String

"android.intent.action.MEDIA_REMOVED"

廣播:擴展介質被移除。

String

"android.intent.action.MEDIA_SCANNER_FINISHED"

廣播:已經掃描完介質的一個目錄。

String

"android.intent.action.MEDIA_SCANNER_STARTED"

廣播:開始掃描介質的一個目錄。

String

"android.intent.action.MEDIA_SHARED"

廣播:擴展介質的掛載被解除 (unmount)

String

"android.intent.action.MEDIA_UNMOUNTED"

廣播:擴展介質存在,可是尚未被掛載 (mount)。

String

"android.intent.action.MWI"

廣播:電話的消息等待(語音郵件)狀態已經改變。

String

"android.intent.action.PACKAGE_ADDED"

廣播:設備上新安裝了一個應用程序包。

String

"android.intent.action.PACKAGE_REMOVED"

廣播:設備上刪除了一個應用程序包。

String

"android.intent.action.PHONE_STATE"

廣播:電話狀態已經改變。

String

"android.intent.action.PROVIDER_CHANGED"

廣播:更新將要(真正)被安裝。

String

"android.intent.action.PROVISIONING_CHECK"

廣播:要求provisioning service下載最新的設置

String

"android.intent.action.SCREEN_OFF"

廣播:屏幕被關閉。

String

"android.intent.action.SCREEN_ON"

廣播:屏幕已經被打開。

String

"android.intent.action.NETWORK_TICKLE_RECEIVED"

廣播:設備收到了新的網絡 "tickle" 通知。

String

"android.intent.action.STATISTICS_REPORT"

廣播:要求 receivers 報告本身的統計信息。

String

"android.intent.action.STATISTICS_STATE_CHANGED"

廣播:統計信息服務的狀態已經改變。

String

"android.intent.action.CFF"

廣播:語音電話的呼叫轉移狀態已經改變。

String

"android.intent.action.CONFIGURATION_CHANGED"

廣播:設備的配置信息已經改變,參見 Resources.Configuration

String

"android.intent.category.ALTERNATIVE"

類別:說明activity是用戶正在瀏的數據的一個可選操做。

String

"android.intent.category.WALLPAPER"

類別:這個 activity 能過爲設備設置牆紙。

String

"android.intent.category.UNIT_TEST"

類別:應該被用做單元測試(經過 test harness 運行)。

String

"android.intent.category.TEST"

類別:做爲測試目的使用,不是正常的用戶體驗的一部分。

String

"android.intent.category.TAB"

類別:activity應該在TabActivity中做爲一個tab使用

String

"android.intent.category.SAMPLE_CODE"

類別:To be used as an sample code example (not part of the normal user experience).

String

"android.intent.category.PREFERENCE"

類別:activity是一個設置面板 (preference panel)。

String

"android.intent.category.HOME"

類別:主屏幕 (activity),設備啓動後顯示的第一個 activity。

String

"android.intent.category.BROWSABLE"

類別:可以被瀏覽器安全使用的 activities 必須支持這個類別。

String

"android.intent.category.DEFAULT"

類別:若是 activity 是對數據執行確省動做(點擊, center press)的一個選項,須要設置這個類別。

String

"android.intent.category.DEVELOPMENT_PREFERENCE"

類別:說明 activity 是一個設置面板 (development preference panel).

String

"android.intent.category.EMBED"

類別:可以在上級(父)activity 中運行。

String

"android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST"

類別:To be used as code under test for framework instrumentation tests.

String

"android.intent.category.GADGET"

類別:這個 activity 能夠被嵌入宿主 activity (activity that is hosting gadgets)。

String

"android.intent.category.LAUNCHER"

類別:Activity 應該被顯示在頂級的 launcher 中。

String

"android.intent.category.SELECTED_ALTERNATIVE"

類別:對於被用戶選中的數據,activity 是它的一個可選操做。

int

8 0x00000008

啓動標記:和 NEW_TASK_LAUNCH 聯合使用,禁止將已有的任務改變爲前景任務 (foreground)。

int

4 0x00000004

啓動標記:設置之後,activity 將成爲歷史堆棧中的第一個新任務(棧頂)。

int

1 0x00000001

啓動標記:設置之後,新的 activity 不會被保存在歷史堆棧中。

int

2 0x00000002

啓動標記:設置之後,若是 activity 已經啓動,並且位於歷史堆棧的頂端,將再也不啓動(不從新啓動) activity。

int

16 0x00000010

啓動標記:若是這個標記被設置,並且被一個已經存在的 activity 用來啓動新的 activity,已有 activity 的回覆目標 (reply target) 會被轉移給新的 activity。

String

"android.intent.extra.INTENT"

附加數據:和 PICK_ACTIVITY_ACTION 一塊兒使用時,說明用戶選擇的用來顯示的 activity;和 ADD_SHORTCUT_ACTION 一塊兒使用的時候,描述要添加的快捷方式。

String

"android.intent.extra.LABEL"

附加數據:大寫字母開頭的字符標籤,和 ADD_SHORTCUT_ACTION 一塊兒使用。

String

"android.intent.extra.TEMPLATE"

附加數據:新記錄的初始化模板。

Creator

相關文章
相關標籤/搜索