Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android--外部啟動activity,自定義action,action常量大全

android--外部啟動activity,自定義action,action常量大全

編輯:關於Android編程

從任意app,啟動另外一個app的activity: 1. Intent i = new Intent(); ComponentName cn = new ComponentName("com.book.android2", "com.book.android2.AndroidSearch"); i.setComponent(cn); i.setAction("android.intent.action.MAIN"); startActivity(i); //orstartActivityForResult(i, RESULT_OK); 我用這種方法時,絕大部分應用可以啟動,但是像RootExplorer卻無法啟動,出現FC對話框,因此建議使用下面這種方式: 2. Intent it = new Intent("android.intent.action.MAIN"); it.setClassName("com.speedsoftware.rootexplorer","com.speedsoftware.rootexplorer.RootExplorer"); startActivity(it);   如果你需要啟動一個你自己寫的另一個app的activity,你可以在那個的menifest.xml裡自定義activity的action:   com.qylk.call.main"/> android.intent.action.MAIN"/> android.intent.category.LAUNCHER"/> android.intent.category.DEFAULT"/>   其他地方啟動它:Intent it = new Intent("com.qylk.call.main"); startActivity(it);   3.使用adb啟動activity: 啟動RootExolorer: am start -a android.intent.action.MAIN -n com.speedsoftware.rootexplorer/.RootExplorer 啟動系統設置: am start -a android.settings.SETTINGS   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:[email protected]"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); startActivity(it);   Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_EMAIL, "[email protected]"); 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={"[email protected]"}; String[] ccs={"[email protected]"}; 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.卸載 Uri uri = Uri.fromParts("package", strPackageName, null); Intent it = new Intent(Intent.ACTION_DELETE, uri); startActivity(it);   12.安裝 Uri installUri = Uri.fromParts("package", "xxx", null); returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);   13. 打開照相機 Intent i = new Intent(Intent.ACTION_CAMERA_BUTTON, null); this.sendBroadcast(i);   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);       17.尋找應用 剛才找app id未果,結果發現用package name也可以 Uri uri = Uri.parse("market://details?id="); 這個簡單多了   Uri uri = Uri.parse("market://search?q=pname:pkg_name"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);   18.打開聯系人列表 Intent i = new Intent(); i.setAction(Intent.ACTION_GET_CONTENT); i.setType("vnd.android.cursor.item/phone"); startActivityForResult(i, REQUEST_TEXT);   Uri uri = Uri.parse("content://contacts/people"); Intent it = new Intent(Intent.ACTION_PICK, uri); startActivityForResult(it, REQUEST_TEXT);   20.調用系統編輯添加聯系人(高版本SDK有效): Intent it = new Intent(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 = new Intent(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, "[email protected]"); intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK); startActivity(intent);       23.最基本的share 信息的intent,可以傳一段text信息到各個手機上已安裝程序:如SMS,Email,sina微波,米聊,facebook,twitter等等 Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_TEXT, "The email subject text"); it.setType("text/plain"); startActivity(Intent.createChooser(it, "Choose Email Client"));     ★intent action大全: ACTION_MAIN 作為一個主要的進入口,而並不期望去接受數據 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已經從系統中移除   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   SETTING: 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   在android SDK文檔中有這樣一個類,android.provider.Settings類提供android系統各個頁面的跳轉常量: 使用實例例:startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)),即可跳到android手機網絡設置頁面。 如果要launch Mobile Networks Setting頁面按如下方法: Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); ComponentName cName = new ComponentName(“com.android.phone”,”com.android.phone.Settings”); intent.setComponent(cName); startActivity(intent);   如果要進入Networks Operators頁面按如下方法: Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName(“com.android.phone”, “com.android.phone.NetworkSetting”); startActivity(intent);   String ACTION_ACCESSIBILITY_SETTINGS 輔助功能模塊的顯示設置。 Activity Action: Show settings for accessibility modules. String ACTION_ADD_ACCOUNT 顯示屏幕上創建一個新帳戶添加帳戶。 Activity Action: Show add account screen for creating a new account. String ACTION_AIRPLANE_MODE_SETTINGS 顯示設置,以允許進入/退出飛行模式。 Activity Action: Show settings to allow entering/exiting airplane mode. String ACTION_APN_SETTINGS 顯示設置,以允許配置的APN。 Activity Action: Show settings to allow configuration of APNs. String ACTION_APPLICATION_DETAILS_SETTINGS 有關特定應用程序的詳細信息的顯示屏幕。 Activity Action: Show screen of details about a particular application. String ACTION_APPLICATION_DEVELOPMENT_SETTINGS 顯示設置,以允許應用程序開發相關的設置配置 Activity Action: Show settings to allow configuration of application development-related settings. String ACTION_APPLICATION_SETTINGS 顯示設置,以允許應用程序相關的設置配置 Activity Action: Show settings to allow configuration of application-related settings. String ACTION_BLUETOOTH_SETTINGS 顯示設置,以允許藍牙配置 Activity Action: Show settings to allow configuration of Bluetooth. String ACTION_DATA_ROAMING_SETTINGS 選擇of2G/3G顯示設置 Activity Action: Show settings for selection of2G/3G. String ACTION_DATE_SETTINGS 顯示日期和時間設置,以允許配置 Activity Action: Show settings to allow configuration of date and time. String ACTION_DEVICE_INFO_SETTINGS 顯示一般的設備信息設置(序列號,軟件版本,電話號碼,等) Activity Action: Show general device information settings (serial number, software version, phone number, etc.). String ACTION_DISPLAY_SETTINGS 顯示設置,以允許配置顯示 Activity Action: Show settings to allow configuration of display. String ACTION_INPUT_METHOD_SETTINGS 特別配置的輸入方法,允許用戶啟用輸入法的顯示設置 Activity Action: Show settings to configure input methods, in particular allowing the user to enable input methods. String ACTION_INPUT_METHOD_SUBTYPE_SETTINGS 顯示設置來啟用/禁用輸入法亞型 Activity Action: Show settings to enable/disable input method subtypes. String ACTION_INTERNAL_STORAGE_SETTINGS 內部存儲的顯示設置 Activity Action: Show settings for internal storage. String ACTION_LOCALE_SETTINGS 顯示設置,以允許配置的語言環境 Activity Action: Show settings to allow configuration of locale. String ACTION_LOCATION_SOURCE_SETTINGS 顯示設置,以允許當前位置源的配置 Activity Action: Show settings to allow configuration of current location sources. String ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS 顯示設置來管理所有的應用程序 Activity Action: Show settings to manage all applications. String ACTION_MANAGE_APPLICATIONS_SETTINGS 顯示設置來管理安裝的應用程序 Activity Action: Show settings to manage installed applications. String ACTION_MEMORY_CARD_SETTINGS 顯示設置為存儲卡存儲 Activity Action: Show settings for memory card storage. String ACTION_NETWORK_OPERATOR_SETTINGS 選擇網絡運營商的顯示設置 Activity Action: Show settings for selecting the network operator. String ACTION_PRIVACY_SETTINGS 顯示設置,以允許配置隱私選項 Activity Action: Show settings to allow configuration of privacy options. String ACTION_QUICK_LAUNCH_SETTINGS 顯示設置,以允許快速啟動快捷鍵的配置 Activity Action: Show settings to allow configuration of quick launch shortcuts. String ACTION_SEARCH_SETTINGS 全局搜索顯示設置 Activity Action: Show settings for global search. String ACTION_SECURITY_SETTINGS 顯示設置,以允許配置的安全性和位置隱私 Activity Action: Show settings to allow configuration of security and location privacy. String ACTION_SETTINGS 顯示系統設置 Activity Action: Show system settings. String ACTION_SOUND_SETTINGS 顯示設置,以允許配置聲音和音量 Activity Action: Show settings to allow configuration of sound and volume. String ACTION_SYNC_SETTINGS 顯示設置,以允許配置同步設置 Activity Action: Show settings to allow configuration of sync settings. String ACTION_USER_DICTIONARY_SETTINGS 顯示設置來管理用戶輸入字典 Activity Action: Show settings to manage the user input dictionary. String ACTION_WIFI_IP_SETTINGS 顯示設置,以允許配置一個靜態IP地址的Wi – Fi Activity Action: Show settings to allow configuration of a static IP address for Wi-Fi. String ACTION_WIFI_SETTINGS 顯示設置,以允許Wi – Fi配置 Activity Action: Show settings to allow configuration of Wi-Fi. String ACTION_WIRELESS_SETTINGS 顯示設置,以允許配置,如Wi – Fi,藍牙和移動網絡的無線控制 Activity Action: Show settings to allow configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks. String AUTHORITY String EXTRA_AUTHORITIES 在推出活動的基礎上給予的權力限制可選項。 Activity Extra: Limit available options in launched activity based on the given authority. String EXTRA_INPUT_METHOD_ID
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved