1. 程式人生 > >Android 外部啟動activity,自定義action,action常量大全

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

https://www.cnblogs.com/guop/p/5067342.html

從任意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); //or startActivityForResult(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:

< activity  android:name =" .MainActivity "  android:label =" @string/app_name " android:theme =" 

@android :style/Theme.Black.NoTitleBar.Fullscreen " >

<intent-filter>

  <action android:name=" com.qylk.call.main" />    <!-- 自定義的action-->

  <action android:name=" android.intent.action.MAIN" />

  <category android:name=" android.intent.category.LAUNCHER" />

  <category android:name=" android.intent.category.DEFAULT" /><!--必須加上這個,否則下面無法直接使用自定的action-->

  </intent-filter>

  </activity>

 

其他地方啟動它: 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

 

附(轉載):android系統Action常量(其實不算全)

android intent和intent action大全 

 

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); 

 //<uses-permission id="android.permission.CALL_PHONE" /> 

 

 

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=<packagename>"); 

這個簡單多了 

 

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