語言

Service 類別

定義

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

[Android.Runtime.Register("android/app/Service", DoNotGenerateAcw=true)]
public abstract class Service : Android.Content.ContextWrapper, Android.Content.IComponentCallbacks2, IDisposable
[<Android.Runtime.Register("android/app/Service", DoNotGenerateAcw=true)>]
type Service = class
    inherit ContextWrapper
    interface IComponentCallbacks
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComponentCallbacks2
繼承
衍生
屬性
實作

備註

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。 每個服務類別必須在其套件的 AndroidManifest.xml中擁有對應 <的服務> 宣告。 服務可使用 Context.startService() 和 Context.bindService() 啟動。 請注意,服務和其他應用程式物件一樣,都是在其主機程序的主執行緒中執行。 這表示,如果你的服務要執行任何 CPU 密集型(例如 MP3 播放)或阻塞性(例如網路)操作,它應該會自行生成執行緒來執行這些工作。 更多相關資訊可參見《流程與線程》。 JobIntentService 類別作為 Service 的標準實作提供,擁有自己的執行緒,負責排程工作。

這裡涵蓋的主題:什麼是服務? 服務生命週期權限流程生命週期 本地服務範例 遠端通訊服務範例開發者指南 欲詳細討論如何建立服務,請閱讀服務開發者指南。

關於服務類別的大多數混淆其實圍繞在它不是什麼:

因此,服務本身其實非常簡單,提供兩個主要功能:

當實際建立服務元件時,基於上述任一原因,系統實際上所做的只是實例化該元件,並呼叫其 onCreate() 及主執行緒上的其他適當回調。 服務需以適當行為實作這些執行緒,例如建立次要執行緒以執行任務。

請注意,因為 Service 本身非常簡單,你可以讓與它的互動變得簡單或複雜:從把它當作本地 Java 物件直接呼叫方法(如 Local Service Sample 所示),到提供完整的遠端介面,使用 AIDL。

系統能執行服務有兩個原因。 如果有人呼叫 Context.startService(),系統會擷取該服務(建立服務並在需要時呼叫其 onCreate() 方法),然後用客戶端提供的參數呼叫 onStartCommand(Intent, int, int) 方法。 此時服務會繼續運行,直到呼叫 Context.stopService() 或 stopSelf() 為止。 請注意,多次呼叫 Context.startService() 不會巢狀(雖然會導致多次對應 onStartCommand()的呼叫),因此無論啟動多少次,一旦呼叫 Context.stopService() 或 stopSelf() 時,服務都會被停止;然而,服務可以使用 stopSelf(int) 方法確保服務在啟動意圖處理完成前不會停止。 對於啟動服務,還有兩種主要操作模式可依據從 onStartCommand() 回傳的值決定執行:START_STICKY 用於明確啟動與停止的服務,而 START_NOT_STICKY 或 START_REDELIVER_INTENT 用於僅在處理指令時仍應持續運行的服務。 詳見連結文件以了解語意細節。 用戶端也可以使用 Context.bindService() 來取得與服務的持久連線。 同樣地,若服務尚未執行(呼叫 onCreate() 並呼叫),則會建立該服務,但不會呼叫 onStartCommand()。 用戶端會收到服務從 onBind(Intent) 方法回傳的 IBinder 物件,讓用戶端能夠回調服務。 只要連線建立(無論用戶端是否保留服務 IBinder 上的參考),服務就會持續運行。 通常回傳的 IBinder 是針對一個在 aidl 中撰寫的複雜介面。 服務可以同時啟動,並且有綁定連線。 在這種情況下,只要服務啟動或有一個或多個帶有Context.BIND_AUTO_CREATE標誌的連線,系統就會持續運作。 當這兩種情況都不成立時,會呼叫服務的 onDestroy() 方法,服務即自動終止。 所有清理(停止執行緒、取消註冊接收器)在從 onDestroy() 返回時應該會完成。 當服務在清單 <的服務> 標籤中宣告時,可以強制執行對服務的全域存取權限。 如此一來,其他應用程式就必須在自己的清單中宣告對應 <的使用權限> 元素,才能啟動、停止或綁定服務。 截至Build.VERSION_CODES年。GINGERBREAD,使用 Context.startService(Intent) 時,你也可以在 Intent 上設定 Intent.FLAG_GRANT_READ_URI_PERMISSION 和/或 Intent.FLAG_GRANT_WRITE_URI_PERMISSION。 此時服務將暫時存取意圖中的特定 URI。 存取權限將持續存在,直到服務呼叫 stopSelf(int) 以執行該啟動指令或後續指令,或服務完全停止為止。 這適用於授權未申請保護服務的其他應用程式,甚至服務未匯出時的存取權限。 此外,服務可在執行呼叫實作前,呼叫 ContextWrapper.checkCallingPermission(String) 方法,以權限保護個別 IPC 呼叫。 欲了解更多關於權限與安全性的資訊,請參閱《安全與權限文件》。 程序生命週期 Android 系統會嘗試讓該程序持續存在,只要服務已經啟動或有綁定用戶端。 當記憶體不足且需要終止現有程序時,承載該服務的程序優先順序會是以下可能性中較高者:若服務目前正以 onCreate()、onStartCommand() 或 onDestroy() 方法執行程式碼,則該託管程序將成為前台程序,以確保該程式碼能執行而不被終止。 如果服務已經啟動,則其託管程序被視為不如目前使用者在螢幕上可見的程序重要,但比任何不可見的程序更重要。 由於使用者通常只看到少數程序,這表示除非在記憶體不足的情況下,否則不應終止服務。 然而,由於使用者並未直接知道背景服務,在該狀態下該服務被視為有效的殺害候選,你應該為這種情況做好準備。 尤其是長期營運的服務,若持續運作足夠久,將越來越可能導致死亡,且若持續足夠久,必定會被終止(並在適當情況下重新啟動)。 如果有客戶端綁定於該服務,那麼服務的主機流程永遠不會比最重要的客戶端低。 也就是說,如果其中一個用戶端對使用者可見,那麼該服務本身就被視為可見。 客戶重要性如何影響服務的重要性,可以透過Context.BIND_ABOVE_CLIENT、Context.BIND_ALLOW_OOM_MANAGEMENT、Context.BIND_WAIVE_PRIORITY、Context.BIND_IMPORTANT和Context.BIND_ADJUST_WITH_ACTIVITY來調整。 啟動服務可使用 startForeground(int,Notification) API 將服務置於前景狀態,系統會認為使用者已主動察覺,因此不會在記憶體不足時終止服務。 (理論上,服務仍可能因當前前景應用程式的極端記憶體壓力而終止,但實務上這不應成為問題。)請注意,這表示大多數服務在執行時,如果系統承受過重記憶體壓力,服務可能會被終止。 如果發生這種情況,系統之後會嘗試重新啟動服務。 這其中一個重要後果是,如果你實作 onStartCommand() 來排程工作非同步或在其他執行緒中完成,那麼你可能會想用 START_FLAG_REDELIVERY 讓系統重新交付意圖,避免在處理過程中服務中斷時意圖遺失。 與其他應用程式元件(例如活動)在同一程序中運行,當然可以提升整體流程的重要性,而不僅僅是服務本身的重要性。 本地服務範例 服務最常見的用途之一是作為次要元件,與應用程式的其他部分並行運行,與其他元件相同。 除非特別說明,否則.apk的所有元件都會在同一程序中運行,因此這是典型情況。 以這種方式使用,假設元件處於相同流程,可以大幅簡化它們之間的互動:服務的客戶端只需將從中收到的 IBinder 鑄造成服務發布的具體類別。 此處展示了服務的使用範例。 首先是服務本身,綁定時會發布一個自訂類別:完成後,就可以撰寫直接存取執行中的服務的客戶端程式碼,例如:遠端 Messenger Service 範例 如果你需要能夠撰寫一個能與遠端程序中的客戶端進行複雜通訊的服務(超越單純使用 Context.startService 發送指令), 這樣你就可以使用 Messenger 類別,而不是寫完整的 AIDL 檔案。 這裡展示了一個以 Messenger 作為用戶端介面的服務範例。 首先是服務本身,綁定後會將 Messenger 發佈給內部處理程序:如果我們想讓此服務在遠端程序中執行(而非標準程序的 .apk),可以在其 manifest 標籤中使用 android:process 來指定:請注意,這裡選擇的「remote」名稱是任意的,如果你想要更多程序,也可以使用其他名稱。 「:」前綴會將名稱附加到你套件的標準流程名稱後面。 完成後,客戶端即可綁定服務並發送訊息。 請注意,這也允許用戶端註冊以接收回傳訊息:

Android 參考資料。android.app.Service

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

建構函式

名稱 Description
Service()
Service(IntPtr, JniHandleOwnership)

初始化現有 Java 原生介面物件的受管理表示。

欄位

名稱 Description
AccessibilityService

使用 with #getSystemService(String) 來取得 a android.view.accessibility.AccessibilityManager ,以便透過註冊事件監聽器向使用者提供 UI 事件的回饋。

(繼承來源 Context)
AccountService

使用 with #getSystemService(String) 來取得 a android.accounts.AccountManager 以在你選擇的時間接收意圖。

(繼承來源 Context)
ActivityService

使用 來 #getSystemService(String) 取得 a android.app.ActivityManager 以與全域系統狀態互動。

(繼承來源 Context)
AdvancedProtectionService

使用 以 #getSystemService(String) 取得 android.security.advancedprotection.AdvancedProtectionManager

(繼承來源 Context)
AlarmService

使用 with #getSystemService(String) 來取得 a android.app.AlarmManager 以在你選擇的時間接收意圖。

(繼承來源 Context)
AppFunctionService

用 來#getSystemService(String)取得執行應用程式函式的 。AppFunctionManager

(繼承來源 Context)
AppInteractionService

用 with #getSystemService(String) 來取得 an android.app.AppInteractionManager 來管理應用程式互動。

(繼承來源 Context)
AppOpsService

使用 with #getSystemService(String) 來取得 a android.app.AppOpsManager 以追蹤裝置上的應用程式操作。

(繼承來源 Context)
AppSearchService

用 來 #getSystemService(String) 取得 android.app.appsearch.AppSearchManager 系統管理的索引與查詢應用程式資料。

(繼承來源 Context)
AppwidgetService

使用 with #getSystemService(String) 來取得 a android.appwidget.AppWidgetManager 以存取 AppWidgets。

(繼承來源 Context)
AudioService

使用來 #getSystemService(String) 取得 a android.media.AudioManager ,以處理音量管理、鈴聲模式及音訊路由。

(繼承來源 Context)
AuthenticationPolicyService

使用 以 #getSystemService(String) 取得 android.security.authenticationpolicy.AuthenticationPolicyManager

(繼承來源 Context)
AutofillService

使用 以 #getSystemService(String) 取得 android.view.autofill.AutofillManager

(繼承來源 Context)
BatteryService

用 來 #getSystemService(String) 取得 a android.os.BatteryManager 來管理電池狀態。

(繼承來源 Context)
BindAllowActivityStarts
已淘汰.

標記 #bindService:若綁定來自可見的應用程式,綁定服務可從背景啟動活動。

(繼承來源 Context)
BindExternalServiceLong

其運作方式與 相同 #BIND_EXTERNAL_SERVICE,但定義為 longBindServiceFlags相容的值。

(繼承來源 Context)
BindNotPerceptible
已淘汰.

標記: #bindService若綁定來自可見或使用者可感知的應用程式,則將目標服務的重要性降至可感知以下。

(繼承來源 Context)
BindPackageIsolatedProcess
已淘汰.

標記 #bindIsolatedService:將服務綁定為共享的獨立程序,但僅限於與同一套件中宣告相同程序名稱的其他孤立服務綁定。

(繼承來源 Context)
BindSharedIsolatedProcess
已淘汰.

標記為 #bindIsolatedService:將服務綁定成共享且隔離的程序。

(繼承來源 Context)
BiometricService

用 with #getSystemService(String) 來取得 a android.hardware.biometrics.BiometricManager 來處理生物識別和 PIN/模式/密碼驗證。

(繼承來源 Context)
BlobStoreService

使用 with #getSystemService(String) 來取得 a android.app.blob.BlobStoreManager ,以便貢獻並存取系統維護的 blob 儲存庫中的資料 blob。

(繼承來源 Context)
BluetoothService

用 來 #getSystemService(String) 取得 a android.bluetooth.BluetoothManager 以使用藍牙。

(繼承來源 Context)
BugreportService

服務用來擷取錯誤報告。

(繼承來源 Context)
CameraService

用 來 #getSystemService(String) 取得 a android.hardware.camera2.CameraManager 以與相機裝置互動。

(繼承來源 Context)
CaptioningService

使用 with #getSystemService(String) 來取得 android.view.accessibility.CaptioningManager 字幕屬性並聆聽字幕偏好的變化。

(繼承來源 Context)
CarrierConfigService

使用 來 #getSystemService(String) 取得 a android.telephony.CarrierConfigManager 以讀取載波配置值。

(繼承來源 Context)
ChooserService

使用 with #getSystemService(String) 來取得 android.service.chooser.ChooserManager

(繼承來源 Context)
ClipboardService

使用 with #getSystemService(String) 來取得 a android.content.ClipboardManager ,以便存取並修改全域剪貼簿的內容。

(繼承來源 Context)
CompanionDeviceService

使用 with #getSystemService(String) 來取得 a android.companion.CompanionDeviceManager 以管理伴隨裝置

(繼承來源 Context)
ConnectivityDiagnosticsService

使用來 #getSystemService(String) 取得 a android.net.ConnectivityDiagnosticsManager ,以執行網路連接診斷,並從系統接收網路連接資訊。

(繼承來源 Context)
ConnectivityService

使用 with #getSystemService(String) 來取得 a android.net.ConnectivityManager 以處理網路連線管理。

(繼承來源 Context)
ConsumerIrService

使用時 #getSystemService(String) 可從裝置擷取 a android.hardware.ConsumerIrManager 以傳送紅外線訊號。

(繼承來源 Context)
ContactKeysService

使用來 #getSystemService(String) 取得 A E2eeContactKeysManager 以管理聯絡金鑰。

(繼承來源 Context)
ContentRestrictionService

使用 with #getSystemService(String) 來取得 android.app.contentsafety.ContentSafetyManager

(繼承來源 Context)
CredentialService

使用 with #getSystemService(String) 來取得 a android.credentials.CredentialManager 以驗證使用者到你的應用程式。

(繼承來源 Context)
CrossProfileAppsService

使用 with #getSystemService(String) 來取得交叉剖面操作的 a android.content.pm.CrossProfileApps

(繼承來源 Context)
DeviceIdDefault

預設裝置 ID,即主要(非虛擬)裝置的 ID。

(繼承來源 Context)
DeviceIdInvalid

裝置 ID 無效。

(繼承來源 Context)
DeviceLockService

使用 with #getSystemService(String) 來取得 android.devicelock.DeviceLockManager

(繼承來源 Context)
DevicePolicyService

使用 with #getSystemService(String) 來取得 a android.app.admin.DevicePolicyManager ,以便處理全域裝置政策管理。

(繼承來源 Context)
DisplayHashService

使用 to #getSystemService(String) 存取 android.view.displayhash.DisplayHashManager 來處理顯示雜湊值。

(繼承來源 Context)
DisplayService

使用 with #getSystemService(String) 來取得 a android.hardware.display.DisplayManager 以與顯示裝置互動。

(繼承來源 Context)
DomainVerificationService

使用 to #getSystemService(String) 存取 android.content.pm.verify.domain.DomainVerificationManager 權以取得已宣告網域的審核與使用者狀態。

(繼承來源 Context)
DownloadService

使用 with #getSystemService(String) 來取得 a android.app.DownloadManager 以請求 HTTP 下載。

(繼承來源 Context)
DropboxService

用 來 #getSystemService(String) 擷取 android.os.DropBoxManager 一個實例來記錄診斷日誌。

(繼承來源 Context)
EuiccService

用 來 #getSystemService(String) 取得 a android.telephony.euicc.EuiccManager 來管理裝置 eUICC(嵌入式 SIM)。

(繼承來源 Context)
FileIntegrityService

使用 以 #getSystemService(String) 取得 android.security.FileIntegrityManager

(繼承來源 Context)
FileService

使用 with #getSystemService(String) 來取得 a android.os.storage.FileManager 以處理檔案操作。

(繼承來源 Context)
FingerprintService

使用來 #getSystemService(String) 取得指紋管理的 a android.hardware.fingerprint.FingerprintManager

(繼承來源 Context)
GameService

使用 with #getSystemService(String) 來取得 GameManager

(繼承來源 Context)
GrammaticalInflectionService

使用 with #getSystemService(String) 來取得 GrammaticalInflectionManager

(繼承來源 Context)
HardwarePropertiesService

使用 with #getSystemService(String) 來取得 a android.os.HardwarePropertiesManager 以存取硬體屬性服務。

(繼承來源 Context)
HealthconnectService

使用 with #getSystemService(String) 來取得 android.health.connect.HealthConnectManager

(繼承來源 Context)
HidService

使用 with #getSystemService(String) 來取得 a android.hardware.hid.HidManager 以與 HID 裝置互動。

(繼承來源 Context)
InputMethodService

使用 with #getSystemService(String) 來取得 a android.view.inputmethod.InputMethodManager 以存取輸入方法。

(繼承來源 Context)
InputService

使用 來 #getSystemService(String) 取得 a android.hardware.input.InputManager 以與輸入裝置互動。

(繼承來源 Context)
IpsecService

使用 with #getSystemService(String) 來取得 a android.net.IpSecManager 以加密 IPSec 的 Sockets 或網路。

(繼承來源 Context)
JobSchedulerService

用 with #getSystemService(String) 來取得 android.app.job.JobScheduler 一個實例,用於管理偶爾的背景任務。

(繼承來源 Context)
KeychainService

使用 with #getSystemService(String) 來取得 a android.security.KeyChainManager 以管理鑰匙圈憑證與授權。

(繼承來源 Context)
KeyguardService

用 來 #getSystemService(String) 取得 a android.app.KeyguardManager 以控制 Keyguard。

(繼承來源 Context)
KeystoreService

使用 with #getSystemService(String) 來取得 a android.security.keystore.KeyStoreManager 以存取 Android Keystore 函式。

(繼承來源 Context)
LauncherAppsService

使用 with #getSystemService(String) 來取得 android.content.pm.LauncherApps 查詢並監控可啟動應用程式的用戶檔案。

(繼承來源 Context)
LayoutInflaterService

在此語境下,使用 with #getSystemService(String) 來取得 a android.view.LayoutInflater ,以膨脹版面資源。

(繼承來源 Context)
LocaleService

使用 with #getSystemService(String) 來取得 android.app.LocaleManager

(繼承來源 Context)
LocationService

使用 with #getSystemService(String) 來取得 a android.location.LocationManager 以控制位置更新。

(繼承來源 Context)
MediaCommunicationService

使用 來 #getSystemService(String) 取得 android.media.MediaCommunicationManager 用於管理 android.media.MediaSession2

(繼承來源 Context)
MediaMetricsService

使用 with #getSystemService(String) 來取得 a android.media.metrics.MediaMetricsManager ,以便與裝置上的媒體指標互動。

(繼承來源 Context)
MediaProjectionService

使用 with #getSystemService(String) 來取得 android.media.projection.MediaProjectionManager 管理媒體投影會話的實例。

(繼承來源 Context)
MediaQualityService

使用 with #getSystemService(String) 來取得 a android.media.quality.MediaQualityManager ,以標準化圖片和音訊 API 參數。

(繼承來源 Context)
MediaRouterService

使用 with #getSystemService 來取得 a android.media.MediaRouter 以控制和管理媒體路由。

(繼承來源 Context)
MediaSessionService

使用 with #getSystemService(String) 來取得 a android.media.session.MediaSessionManager 以管理媒體會話。

(繼承來源 Context)
MemoryBudgetService

用 來 #getSystemService(String) 取得 a android.app.MemoryBudgetManager 以監控記憶體預算。

(繼承來源 Context)
MidiService

使用 with #getSystemService(String) 來取得 a android.media.midi.MidiManager 以存取 MIDI 服務。

(繼承來源 Context)
MultisensoryManagerService

用來 #getSystemService(String) 取得播放多感官回饋的服務。

(繼承來源 Context)
NetworkStatsService

用 來 #getSystemService(String) 取得 a android.app.usage.NetworkStatsManager 以查詢網路使用統計。

(繼承來源 Context)
NfcService

使用 with #getSystemService(String) 來取得 a android.nfc.NfcManager 以使用 NFC。

(繼承來源 Context)
NotificationService

使用 with #getSystemService(String) 來取得 a android.app.NotificationManager ,以通知使用者背景事件。

(繼承來源 Context)
NpuService

使用 with #getSystemService(String) 來取得 android.npumanager.NpuManager

(繼承來源 Context)
NsdService

使用 with #getSystemService(String) 來取得 a android.net.nsd.NsdManager 以處理網路服務發現管理

(繼承來源 Context)
OverlayService

用 來 #getSystemService(String) 取得 a android.content.om.OverlayManager 以管理覆蓋層套件。

(繼承來源 Context)
PccSandboxService

使用 with #getSystemService(String) 來取得 android.app.privatecompute.PccSandboxManager

(繼承來源 Context)
PeopleService

使用 with #getSystemService(String) 來存取 a PeopleManager ,與你已發表的對話互動。

(繼承來源 Context)
PerformanceHintService

使用 來 #getSystemService(String) 取得 a android.os.PerformanceHintManager 以存取效能提示服務。

(繼承來源 Context)
PersistentDataBlockService

用 來 #getSystemService(String) 取得 android.service.persistentdata.PersistentDataBlockManager 一個實例,與存在於出廠重置之間的儲存裝置互動。

(繼承來源 Context)
PowerService

用 來 #getSystemService(String) 取得 a android.os.PowerManager 來控制電源管理,包括「wake locks」,讓你在執行長時間任務時保持裝置開啟。

(繼承來源 Context)
PrintService

android.print.PrintManager 用於列印及列印管理及列印任務。

(繼承來源 Context)
ProfilingService

使用 以 #getSystemService(String) 取得 android.os.ProfilingManager

(繼承來源 Context)
ReceiverExported
已淘汰.

標記: #registerReceiver接收器可接收來自其他應用程式的廣播。

(繼承來源 Context)
ReceiverNotExported
已淘汰.

標記 #registerReceiver:接收器無法接收來自其他應用程式的廣播。

(繼承來源 Context)
ReceiverVisibleToInstantApps
已淘汰.

標記: #registerReceiver接收器可接收來自即時應用程式的廣播。

(繼承來源 Context)
RestrictionsService

使用 with #getSystemService(String) 來取得 a android.content.RestrictionsManager ,用於擷取應用程式限制並請求受限制操作的權限。

(繼承來源 Context)
RoleService

使用 with #getSystemService(String) 來取得管理角色的 a android.app.role.RoleManager

(繼承來源 Context)
SatelliteService

使用 with #getSystemService(String) 來取得 a android.telephony.satellite.SatelliteManager 以存取衛星功能。

(繼承來源 Context)
SearchService

使用 with #getSystemService(String) 來取得 a android.app.SearchManager 以處理搜尋。

(繼承來源 Context)
SecurityStateService

使用 with #getSystemService(String) 來取得 a android.os.SecurityStateManager 以存取安全狀態管理器服務。

(繼承來源 Context)
SensorService

用 來 #getSystemService(String) 取得 a android.hardware.SensorManager 以存取感測器。

(繼承來源 Context)
SerialService

用 來 #getSystemService(String) 取得 a android.hardware.serial.SerialManager 以存取序列埠。

(繼承來源 Context)
ShortcutService

用 with #getSystemService(String) 來取得 a android.content.pm.ShortcutManager 以存取啟動器捷徑服務。

(繼承來源 Context)
StatusBarService

用 來 #getSystemService(String) 取得 a android.app.StatusBarManager ,以便與狀態列互動及快速設定。

(繼承來源 Context)
StopForegroundDetach
已淘汰.

選取器 #stopForeground(int):如果設定,先前提供的 #startForeground 通知將會與服務的生命週期中斷連結。

StopForegroundLegacy

#stopForeground(int)選取器:相當於傳遞 false 至舊版 API #stopForeground(boolean)

StopForegroundRemove
已淘汰.

#stopForeground(int)選取器:如果已提供,先前提供的 #startForeground 通知將會取消並移除顯示。

StorageService

使用 來 #getSystemService(String) 取得 a android.os.storage.StorageManager 以存取系統儲存函數。

(繼承來源 Context)
StorageStatsService

使用 with #getSystemService(String) 來取得 a android.app.usage.StorageStatsManager 以存取系統儲存統計資料。

(繼承來源 Context)
SystemHealthService

用 來 #getSystemService(String) 取得 android.os.health.SystemHealthManager 系統健康(電池、電力、記憶體等)指標。

(繼承來源 Context)
TelecomService

使用 with #getSystemService(String) 來取得 a android.telecom.TelecomManager 以管理裝置的電信相關功能。

(繼承來源 Context)
TelephonyImsService

使用 以 #getSystemService(String) 取得 android.telephony.ims.ImsManager

(繼承來源 Context)
TelephonyPhoneNumberService

使用 with #getSystemService(String) 來取得 a android.telephony.PhoneNumberManager 以解析電話號碼。

(繼承來源 Context)
TelephonyService

使用 來 #getSystemService(String) 取得 a android.telephony.TelephonyManager 以處理裝置的電話功能管理。

(繼承來源 Context)
TelephonySubscriptionService

使用 with #getSystemService(String) 來取得 a android.telephony.SubscriptionManager 以處理裝置的電話訂閱管理。

(繼承來源 Context)
TetheringService

使用 with #getSystemService(String) 來取得 a android.net.TetheringManager 以管理繫網功能。

(繼承來源 Context)
TextClassificationService

使用 with #getSystemService(String) 以取得文字分類服務的 a TextClassificationManager

(繼承來源 Context)
TextServicesManagerService

使用 with #getSystemService(String) 以取得 android.view.textservice.TextServicesManager 文字服務。

(繼承來源 Context)
TimeManagerService

使用 with #getSystemService(String) 來取得 TimeManager

(繼承來源 Context)
TvAdService

使用 with #getSystemService(String) 來取得 a android.media.tv.ad.TvAdManager ,以便與裝置上的電視客戶端廣告服務互動。

(繼承來源 Context)
TvInputService

用 來 #getSystemService(String) 取得 a android.media.tv.TvInputManager 以與裝置上的電視輸入互動。

(繼承來源 Context)
TvInteractiveAppService

使用 with #getSystemService(String) 來取得 a android.media.tv.interactive.TvInteractiveAppManager ,以便與裝置上的電視互動應用程式互動。

(繼承來源 Context)
UiModeService

用 來 #getSystemService(String) 取得 a android.app.UiModeManager 來控制 UI 模式。

(繼承來源 Context)
UsageStatsService

用 來 #getSystemService(String) 取得 a android.app.usage.UsageStatsManager 以查詢裝置使用統計。

(繼承來源 Context)
UsbService

用 來 #getSystemService(String) 取得 A android.hardware.usb.UsbManager ,作為 USB 主機存取 USB 裝置,並控制該裝置作為 USB 裝置的行為。

(繼承來源 Context)
UserService

使用 with #getSystemService(String) 來取得 a android.os.UserManager ,以管理支援多使用者的裝置上的使用者。

(繼承來源 Context)
VibratorManagerService

使用來 #getSystemService(String) 取得 a android.os.VibratorManager ,以便存取裝置震動器、與個別震動器互動,並在多個震動器上播放同步效果。

(繼承來源 Context)
VibratorService

使用來 #getSystemService(String) 取得與振動硬體互動的 a android.os.Vibrator

(繼承來源 Context)
VirtualDeviceService

使用 with #getSystemService(String) 來取得 a android.companion.virtual.VirtualDeviceManager 以管理虛擬裝置。

(繼承來源 Context)
VpnManagementService

使用 with #getSystemService(String) 來取得 a android.net.VpnManager 來管理平台內建 VPN 的設定檔。

(繼承來源 Context)
WallpaperService

用 with #getSystemService(String) 來取回通訊器。

(繼承來源 Context)
WebAppService

使用 with #getSystemService(String) 來取得 android.content.pm.webapp.WebAppManager

(繼承來源 Context)
WifiAwareService

使用 with #getSystemService(String) 來取得 a android.net.wifi.aware.WifiAwareManager 以處理 Wi-Fi Aware。

(繼承來源 Context)
WifiP2pService

使用 with #getSystemService(String) 來取得 a android.net.wifi.p2p.WifiP2pManager 以處理 Wi-Fi 點對點連線的管理。

(繼承來源 Context)
WifiRttRangingService

用 with #getSystemService(String) 來取得 android.net.wifi.rtt.WifiRttManager 帶有 WiFi 的測距裝置。

(繼承來源 Context)
WifiService

使用 with #getSystemService(String) 來取得 a android.net.wifi.WifiManager 以處理 Wi-Fi 存取管理。

(繼承來源 Context)
WindowService

使用 with #getSystemService(String) 來取得 a android.view.WindowManager 以存取系統的視窗管理器。

(繼承來源 Context)

屬性

名稱 Description
Application

回傳擁有這項服務的應用程式。

ApplicationContext

回傳目前程序單一全域應用程式物件的上下文。

(繼承來源 ContextWrapper)
ApplicationInfo

請回傳本情境套件的完整應用程式資訊。

(繼承來源 ContextWrapper)
Assets

回傳一個 AssetManager 實例,針對你的應用程式套件。

(繼承來源 ContextWrapper)
AttributionSource

取得與此情境相關的歸屬來源。

(繼承來源 Context)
AttributionTag

歸因可以在複雜的應用程式中用來邏輯地區分應用程式的各個部分。

(繼承來源 Context)
BaseContext (繼承來源 ContextWrapper)
CacheDir

回傳檔案系統中應用程式專屬快取目錄的絕對路徑。

(繼承來源 ContextWrapper)
Class

回傳此 Object的執行時類別。

(繼承來源 Object)
ClassLoader

回傳一個你可以用來擷取這個套件裡的類別載入器。

(繼承來源 ContextWrapper)
CodeCacheDir

回傳用於儲存快取程式碼的檔案系統中應用程式專屬快取目錄的絕對路徑。

(繼承來源 ContextWrapper)
ContentResolver

回傳一個 ContentResolver 實例,針對你的應用程式套件。

(繼承來源 ContextWrapper)
DataDir

回傳檔案系統中存放所有屬於此應用程式的私有檔案的目錄的絕對路徑。 應用程式不應直接使用此路徑;他們應該改用 getFilesDir() 、getCacheDir() 、getDir(String,int) 或其他儲存 API 來處理這個類別。 若呼叫應用程式移至已採用的儲存裝置,回傳路徑可能會隨時間改變,因此僅應保留相對路徑。 呼叫應用程式在回傳路徑下讀寫檔案不需要額外權限。 退稅檔案

(繼承來源 ContextWrapper)
DeviceId

會取得該上下文所關聯的裝置 ID。

(繼承來源 Context)
Display

取得這個情境所關聯的顯示。

(繼承來源 Context)
ExternalCacheDir

回傳主要外部檔案系統目錄的絕對路徑(該目錄位於 ExternalStorageDirectory 應用程式可放置快取檔案的位置)。

(繼承來源 ContextWrapper)
FilesDir

回傳檔案系統中存放檔案 OpenFileOutput(String, FileCreationMode) 的目錄的絕對路徑。

(繼承來源 ContextWrapper)
ForegroundServiceType

如果服務已透過呼叫成為前景服務 #startForeground(int, Notification)#startForeground(int, Notification, int)#getForegroundServiceType() 會傳回目前的前景服務類型。

Handle

底層 Android 實例的帳號。

(繼承來源 Object)
IsDeviceProtectedStorage

表示此上下文的儲存 API 是否由裝置保護儲存所支援。

(繼承來源 ContextWrapper)
IsRestricted

表示此上下文是否受限。

(繼承來源 Context)
IsUiContext

如果上下文是可存取 、 或 trueWindowManager 等 UI 元件的 UI 上下文android.view.LayoutInflater LayoutInflater,則回傳 android.app.WallpaperManager WallpaperManager

(繼承來源 Context)
JniIdentityHashCode

取得由互通執行時指派給此 Java 對等端的身份雜湊碼。

(繼承來源 Object)
JniManagedPeerState

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
JniPeerMembers

提供 Android.App.Service 的 JNI 綁定基礎設施。

MainExecutor

回傳 和 Executor ,會在與此上下文相關的主執行緒上執行已排隊的任務。

(繼承來源 Context)
MainLooper

回傳當前程序主執行緒的 Looper。

(繼承來源 ContextWrapper)
NoBackupFilesDir

回傳檔案系統目錄的絕對路徑,類似 FilesDir

(繼承來源 ContextWrapper)
ObbDir

回傳該應用程式的 OBB 檔案(若有)可找到的主要外部儲存目錄。

(繼承來源 ContextWrapper)
OpPackageName

回傳這個上下文中應該用於 android.app.AppOpsManager 呼叫的套件名稱,這樣應用程式運維管理員的 UID 驗證就能用這個名稱。

(繼承來源 Context)
PackageCodePath

回傳完整路徑至此情境的主要 Android 套件。

(繼承來源 ContextWrapper)
PackageManager

回傳 PackageManager 實例以查找全域套件資訊。

(繼承來源 ContextWrapper)
PackageName

回傳這個應用程式的套件名稱。

(繼承來源 ContextWrapper)
PackageResourcePath

回傳完整路徑至此情境的主要 Android 套件。

(繼承來源 ContextWrapper)
Params

回傳該上下文所用的參數集合,若是透過 #createContext(ContextParams)建立。

(繼承來源 Context)
PeerReference

取得這個 Java 節點的 JNI 物件參考。

(繼承來源 Object)
Resources

回傳一個應用程式套件的 Resources 實例。

(繼承來源 ContextWrapper)
Theme

回傳與此上下文相關的主題物件。

(繼承來源 ContextWrapper)
ThresholdClass

提供 Android.App.Service 的 JNI 綁定基礎設施。

ThresholdType

提供 Android.App.Service 的 JNI 綁定基礎設施。

UpdateableFlags

取得可更新(即新增或移除)現有連線的綁定標誌清單。

(繼承來源 Context)
Wallpaper
已淘汰.
(繼承來源 ContextWrapper)
WallpaperDesiredMinimumHeight
已淘汰.
(繼承來源 ContextWrapper)
WallpaperDesiredMinimumWidth
已淘汰.
(繼承來源 ContextWrapper)

方法

名稱 Description
AttachBaseContext(Context)

為這個 ContextWrapper 設定基礎上下文。

(繼承來源 ContextWrapper)
BindIsolatedService(Intent, Context+BindServiceFlags, String, IExecutor, IServiceConnection)

請參考 bindIsolatedService(Intent, int, String, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

(繼承來源 Context)
BindIsolatedService(Intent, Int32, String, IExecutor, IServiceConnection)

在孤立服務的特定情況下,這種變化 #bindService 允許呼叫者從單一元件宣告產生多個服務實例。

(繼承來源 Context)
BindService(Intent, Bind, IExecutor, IServiceConnection)

#bindService(Intent, ServiceConnection, int) bindService(Intent, ServiceConnection, int) 執行器一樣,用來控制 ServiceConnection 回調。

(繼承來源 Context)
BindService(Intent, Context+BindServiceFlags, IExecutor, IServiceConnection)

請參見 bindService(Intent, int, Executor, ServiceConnection) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

(繼承來源 Context)
BindService(Intent, IServiceConnection, Bind)

連接應用程式服務,必要時建立它。

(繼承來源 ContextWrapper)
BindService(Intent, IServiceConnection, Context+BindServiceFlags)

請參見 bindService(Intent, ServiceConnection, int) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

(繼承來源 Context)
BindServiceAsUser(Intent, IServiceConnection, Context+BindServiceFlags, UserHandle)

請參考 bindServiceAsUser(Intent, ServiceConnection, int, UserHandle) 呼叫 BindServiceFlags.of(long) 以取得 BindServiceFlags 物件。

(繼承來源 Context)
BindServiceAsUser(Intent, IServiceConnection, Int32, UserHandle)

以與 相同的方式user綁定於給定#bindService的服務。

(繼承來源 Context)
CheckCallingOrSelfPermission(String)

確認是IPC的通話流程 還是您 獲得了特定權限。

(繼承來源 ContextWrapper)
CheckCallingOrSelfUriPermission(Uri, ActivityFlags)

確認 IPC 的通話流程或 是否已獲得存取特定 URI 的權限。

(繼承來源 ContextWrapper)
CheckCallingOrSelfUriPermissions(IList<Uri>, Int32)

確認 IPC <em>或 you</em> 的呼叫過程是否已被授權存取 URI 清單。

(繼承來源 Context)
CheckCallingPermission(String)

確認你所處理的 IPC 的通話流程是否已獲得特定權限。

(繼承來源 ContextWrapper)
CheckCallingUriPermission(Uri, ActivityFlags)

確認呼叫程序及使用者 ID 是否已獲得存取特定 URI 的權限。

(繼承來源 ContextWrapper)
CheckCallingUriPermissions(IList<Uri>, Int32)

確認呼叫程序與 UID 是否已獲得存取 URI 清單的權限。

(繼承來源 Context)
CheckContentUriPermissionFull(Uri, Int32, Int32, ActivityFlags)

確認某個程序和 UID 是否已被授權存取特定內容 URI。

(繼承來源 Context)
CheckPermission(String, Int32, Int32)

判斷該權限是否允許用於系統中執行的特定程序及使用者 ID。

(繼承來源 ContextWrapper)
CheckSelfPermission(String)

確認您是否已獲得特定許可。

(繼承來源 ContextWrapper)
CheckUriPermission(Uri, Int32, Int32, ActivityFlags)

判斷特定程序及使用者 ID 是否已被授權存取特定 URI。

(繼承來源 ContextWrapper)
CheckUriPermission(Uri, String, String, Int32, Int32, ActivityFlags)

檢查 Uri 和一般權限。

(繼承來源 ContextWrapper)
CheckUriPermissions(IList<Uri>, Int32, Int32, Int32)

確認某個程序與 UID 是否已被授權存取 URI 清單。

(繼承來源 Context)
ClearWallpaper()
已淘汰.
(繼承來源 ContextWrapper)
Clone()

建立並回傳此物件的副本。

(繼承來源 Object)
Construct(JniObjectReference, JniObjectReferenceOptions)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
CreateAttributionContext(String)

回傳一個新的 Context 物件,針對目前的 Context,但屬性是不同的標籤。

(繼承來源 Context)
CreateConfigurationContext(Configuration)

回傳一個新的 Context 物件,針對目前的 Context,但其資源會調整以符合給定的配置。

(繼承來源 ContextWrapper)
CreateContext(ContextParams)

建立具有特定屬性與行為的情境。

(繼承來源 Context)
CreateContextForSplit(String)

為該分割名稱回傳一個新的 Context 物件。 新的 Context 有一個 ClassLoader 和 Resources 物件,可以存取分割及其所有相依關係的程式碼/資源。 每次呼叫此方法都會回傳一個新的上下文物件實例;上下文物件不會被共享,但共用狀態(如 ClassLoader 或其他資源)可能會共享,因此上下文本身可以相當輕量。

(繼承來源 ContextWrapper)
CreateDeviceContext(Int32)

從目前上下文回傳一個新 Context 物件,但裝置關聯由 deviceId給出。

(繼承來源 Context)
CreateDeviceProtectedStorageContext()

回傳一個新的上下文物件,用於目前上下文,但其儲存 API 由裝置保護儲存所支援。 在具備直接開機功能的裝置上,儲存在該位置的資料會以綁定於實體裝置的金鑰加密,且在裝置成功開機後,使用者使用憑證(如鎖定模式或 PIN 碼)驗證之前及之後,都能立即存取資料。 由於裝置保護的資料在無需使用者驗證的情況下即可取得,您應謹慎限制使用此上下文儲存的資料。 例如,強烈建議在裝置保護區域儲存敏感的認證憑證或密碼。 若底層裝置無法使用不同金鑰儲存裝置保護與憑證保護的資料,則兩個儲存區域將同時開放。 它們仍作為磁碟上的兩個獨立儲存位置,只有可用性視窗會改變。 每次呼叫此方法都會回傳一個新的上下文物件實例;上下文物件不會共享,但共用狀態(如 ClassLoader、同一配置的其他資源)可能會共享,因此上下文本身可以相當輕量。 退稅資料背景

(繼承來源 ContextWrapper)
CreateDisplayContext(Display)

回傳一個新的上下文物件,用於當前上下文,但其資源調整以符合該顯示的指標。

(繼承來源 ContextWrapper)
CreatePackageContext(String, PackageContextFlags)

為給定的應用程式名稱回傳一個新的 Context 物件。

(繼承來源 ContextWrapper)
CreateWindowContext(Display, Int32, Bundle)

為給定Context的非窗口android.app.Activity activity創造 a Display

(繼承來源 Context)
CreateWindowContext(Int32, Bundle)

為非活動視窗建立一個上下文。

(繼承來源 Context)
DatabaseList()

回傳一組字串,標示與此上下文應用程式套件相關的私有資料庫。

(繼承來源 ContextWrapper)
DeleteDatabase(String)

刪除與此上下文應用程式套件相關的現有私有 SQLiteDatabase。

(繼承來源 ContextWrapper)
DeleteFile(String)

刪除與此上下文應用程式套件相關的指定私有檔案。

(繼承來源 ContextWrapper)
DeleteSharedPreferences(String)

刪除一個現有的共享偏好設定檔案。

(繼承來源 ContextWrapper)
Dispose()

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
Dispose(Boolean)

釋放該 Java 節點所持有的資源。

(繼承來源 Object)
DisposeUnlessReferenced()

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
Dump(FileDescriptor, PrintWriter, String[])

將服務狀態印入給定的串流中。

EnforceCallingOrSelfPermission(String, String)

如果你或你正在處理的 IPC 呼叫程序都沒有獲得特定權限,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforceCallingOrSelfUriPermission(Uri, ActivityFlags, String)

如果 IPC 或 你的 呼叫程序尚未被授權存取特定 URI,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforceCallingPermission(String, String)

如果你正在處理的 IPC 呼叫程序尚未獲得特定權限,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforceCallingUriPermission(Uri, ActivityFlags, String)

如果呼叫程序和使用者 ID 尚未被授權存取特定 URI,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforcePermission(String, Int32, Int32, String)

如果系統中執行的特定程序和使用者 ID 不允許該權限,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforceUriPermission(Uri, Int32, Int32, ActivityFlags, String)

如果某個程序和使用者 ID 尚未被授權存取特定 URI,請拋出 SecurityException

(繼承來源 ContextWrapper)
EnforceUriPermission(Uri, String, String, Int32, Int32, ActivityFlags, String)

同時執行 Uri 和一般授權。

(繼承來源 ContextWrapper)
Equals(Object)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
Equals(Object)

表示是否有其他物體「等同」於此物。

(繼承來源 Object)
FileList()

回傳一個字串陣列,命名與該上下文應用套件相關的私有檔案。

(繼承來源 ContextWrapper)
GetColor(Int32)

回傳與特定資源 ID 相關且依當前主題設計的顏色。

(繼承來源 Context)
GetColorStateList(Int32)

回傳與特定資源 ID 相關聯的色彩狀態清單,並依當前主題做樣式。

(繼承來源 Context)
GetDatabasePath(String)

回傳檔案系統中以 openOrCreateDatabase(String, int, CursorFactory) 建立資料庫的絕對路徑。 若呼叫應用程式移至已採用的儲存裝置,回傳路徑可能會隨時間改變,因此僅應保留相對路徑。

(繼承來源 ContextWrapper)
GetDir(String, FileCreationMode)

擷取並建立一個新的目錄,應用程式可以放置自己的自訂資料檔案。

(繼承來源 ContextWrapper)
GetDrawable(Int32)

回傳一個可繪製的物件,與特定資源 ID 相關聯,並依當前主題做樣式。

(繼承來源 Context)
GetExternalCacheDirs()

回傳所有外部儲存裝置上應用程式專屬目錄的絕對路徑,該應用程式可放置其擁有的快取檔案。

(繼承來源 ContextWrapper)
GetExternalFilesDir(String)

回傳主外部檔案系統目錄的絕對路徑(該 ExternalStorageDirectory位址位於 ),該應用程式可放置其擁有的持久檔案。

(繼承來源 ContextWrapper)
GetExternalFilesDirs(String)

回傳所有外部儲存裝置上應用程式專屬目錄的絕對路徑,該應用程式可放置其擁有的持久檔案。

(繼承來源 ContextWrapper)
GetExternalMediaDirs()
已淘汰.

回傳所有外部儲存裝置上應用程式專屬目錄的絕對路徑,該應用程式可在此放置媒體檔案。

(繼承來源 ContextWrapper)
GetFileStreamPath(String)

回傳檔案系統中建立檔案的絕對路徑,該檔案存放於該 OpenFileOutput(String, FileCreationMode) 檔案中。

(繼承來源 ContextWrapper)
GetHashCode()

回傳物件的雜湊碼值。

(繼承來源 Object)
GetObbDirs()

回傳所有外部儲存裝置上應用程式專屬目錄的絕對路徑,該目錄中可找到應用程式的 OBB 檔案(若有)。

(繼承來源 ContextWrapper)
GetSharedPreferences(String, FileCreationMode)

取回並保留偏好設定檔「名稱」的內容,回傳一個 SharedPreferences,透過它你可以取回並修改其值。

(繼承來源 ContextWrapper)
GetString(Int32, Object[])

回傳應用程式套件預設字串表中的本地化字串。

(繼承來源 Context)
GetString(Int32)

回傳應用程式套件預設字串表中的本地化字串。

(繼承來源 Context)
GetSystemService(Class)

依類別將句柄回傳至系統層級服務。

(繼承來源 Context)
GetSystemService(String)

以名稱將句柄回傳給系統層級服務。

(繼承來源 ContextWrapper)
GetSystemServiceName(Class)

取得由指定類別所代表的系統層級服務名稱。

(繼承來源 ContextWrapper)
GetText(Int32)

從應用程式套件預設字串表回傳一個本地化且有樣式的 CharSequence。

(繼承來源 Context)
GetTextFormatted(Int32)

從應用程式套件預設字串表回傳一個本地化且有樣式的 CharSequence。

(繼承來源 Context)
GrantUriPermission(String, Uri, ActivityFlags)

將特定 Uri 存取權限授予另一個套件,不論該套件是否擁有存取該 Uri 內容提供者的一般權限。

(繼承來源 ContextWrapper)
JavaFinalize()
已淘汰.

當垃圾回收判定該物件不再有相關參考時,由垃圾回收器呼叫。

(繼承來源 Object)
MoveDatabaseFrom(Context, String)

將現有的資料庫檔案從給定的來源儲存上下文移動到這個上下文。 這通常用於升級後的資料在儲存位置間的遷移,例如遷移到裝置保護儲存裝置。 資料庫必須關閉後才能移動。

(繼承來源 ContextWrapper)
MoveSharedPreferencesFrom(Context, String)

將現有的共享偏好設定檔案從給定的來源儲存上下文移到這個上下文。 這通常用於升級後的資料在儲存位置間的遷移,例如移動到裝置保護儲存裝置。

(繼承來源 ContextWrapper)
Notify()

喚醒一個正在該物件監視器上等待的執行緒。

(繼承來源 Object)
NotifyAll()

喚醒所有等待該物件監視器的執行緒。

(繼承來源 Object)
ObtainStyledAttributes(IAttributeSet, Int32[], Int32, Int32)

在此上下文主題中檢索樣式屬性資訊。

(繼承來源 Context)
ObtainStyledAttributes(IAttributeSet, Int32[])

在此上下文主題中檢索樣式屬性資訊。

(繼承來源 Context)
ObtainStyledAttributes(Int32, Int32[])

在此上下文主題中檢索樣式屬性資訊。

(繼承來源 Context)
ObtainStyledAttributes(Int32[])

在此上下文主題中檢索樣式屬性資訊。

(繼承來源 Context)
OnBind(Intent)

把通訊頻道還給服務單位。

OnConfigurationChanged(Configuration)

當裝置設定變更時,系統會呼叫它,而你的元件正在運行。

OnCreate()

系統在服務創建時呼叫。

OnDestroy()

系統會打電話通知服務該服務已不再使用並被移除。

OnLowMemory()

當整體系統記憶體不足時,當正在執行的程序應該會修剪記憶體使用時,就會呼叫這個動作。

OnRebind(Intent)

當新的用戶端已連線到服務時呼叫,之後,它先前已收到通知,指出其 #onUnbind中的所有用戶端都已中斷連線。

OnStart(Intent, Int32)
已淘汰.

此方法在 API 等級 15 中被棄用。

OnStartCommand(Intent, StartCommandFlags, Int32)

每次用戶端透過呼叫 明確啟動服務時,由系統呼叫 android.content.Context#startService,提供它所提供的自變數,以及代表啟動要求的唯一整數令牌。

OnTaskRemoved(Intent)

若服務目前正在執行,且使用者已移除來自該服務應用程式的任務,則會呼叫此服務。

OnTimeout(Int32, ForegroundService)

當特定前景服務類型逾時時,回撥呼叫。

OnTimeout(Int32)

在逾時呼叫的 ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE回呼。

OnTrimMemory(TrimMemory)

當作業系統判斷程序是刪除其程序中不需要記憶體的好時機時,會被呼叫。

OnUnbind(Intent)

當所有用戶端都已從服務發布的特定介面斷線時呼叫。

OpenFileInput(String)

開啟與此上下文應用程式套件相關的私人檔案以進行閱讀。

(繼承來源 ContextWrapper)
OpenFileOutput(String, FileCreationMode)

開啟與此上下文應用程式套件相關的私有檔案以進行撰寫。

(繼承來源 ContextWrapper)
OpenOrCreateDatabase(String, FileCreationMode, SQLiteDatabase+ICursorFactory, IDatabaseErrorHandler)

開啟與此上下文應用程式套件相關的新私有 SQLiteDatabase。

(繼承來源 ContextWrapper)
OpenOrCreateDatabase(String, FileCreationMode, SQLiteDatabase+ICursorFactory)

開啟與此上下文應用程式套件相關的新私有 SQLiteDatabase。

(繼承來源 ContextWrapper)
PeekWallpaper()
已淘汰.
(繼承來源 ContextWrapper)
RebindService(IServiceConnection, Context+BindServiceFlags)

重新綁定一個應用程式服務,並更新了 bind 服務旗標

(繼承來源 Context)
RegisterComponentCallbacks(IComponentCallbacks)

在 Context 的基礎應用程式中新增 ComponentCallbacks 一個新應用程式,該應用程式會與 ComponentCallbacks 活動及其他元件方法的呼叫同時被呼叫。

(繼承來源 Context)
RegisterDeviceIdChangeListener(IExecutor, IIntConsumer)

新增一個裝置 ID,變更監聽器到 Context,當系統更改裝置關聯時會呼叫。

(繼承來源 Context)
RegisterReceiver(BroadcastReceiver, IntentFilter, ActivityFlags)
已淘汰.

註冊以接收意圖廣播,接收端可選擇性地暴露給即時應用程式。 更多資訊請參閱 registerReceiver(BroadcastReceiver, IntentFilter)。 預設情況下,即時應用程式無法與其他應用程式中的接收器互動,這讓你可以公開一個接收器,讓即時應用程式能互動。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。 截至Build.VERSION_CODES年。UPSIDE_DOWN_CAKE ,系統可在應用程式處於快取狀態時,將上下文註冊的廣播放入佇列。 當應用程式離開快取狀態,例如回到前景時,系統會傳送所有排隊的廣播。 某些廣播的多個實例可能會合併成一個廣播。 截至Build.VERSION_CODES年。ICE_CREAM_SANDWICH,使用此方法註冊的接收器會正確遵守廣播意圖所指定的 Intent.setPackage(字串)。 在此之前,這份郵件會被忽略,並送達所有匹配的註冊收件人。 使用這些資料時要小心。 參數接收器 BroadcastReceiver:此值可能為空值。

(繼承來源 ContextWrapper)
RegisterReceiver(BroadcastReceiver, IntentFilter, ReceiverFlags)

註冊以接收意圖廣播,接收端可選擇性地暴露給即時應用程式。 更多資訊請參閱 registerReceiver(BroadcastReceiver, IntentFilter)。 預設情況下,即時應用程式無法與其他應用程式中的接收器互動,這讓你可以公開一個接收器,讓即時應用程式能互動。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。 截至Build.VERSION_CODES年。UPSIDE_DOWN_CAKE ,系統可在應用程式處於快取狀態時,將上下文註冊的廣播放入佇列。 當應用程式離開快取狀態,例如回到前景時,系統會傳送所有排隊的廣播。 某些廣播的多個實例可能會合併成一個廣播。 截至Build.VERSION_CODES年。ICE_CREAM_SANDWICH,使用此方法註冊的接收器會正確遵守廣播意圖所指定的 Intent.setPackage(字串)。 在此之前,這份郵件會被忽略,並送達所有匹配的註冊收件人。 使用這些資料時要小心。 參數接收器 BroadcastReceiver:負責處理廣播的 BroadcastReceiver。 此值可能是零值。

(繼承來源 Context)
RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler, ActivityFlags)
已淘汰.

註冊以接收意圖廣播,以便在排程器情境下執行。 更多資訊請參見 registerReceiver(BroadcastReceiver,IntentFilter,整數)與 registerReceiver(BroadcastReceiver,IntentFilter,String,Handler)。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。 截至Build.VERSION_CODES年。UPSIDE_DOWN_CAKE ,系統可在應用程式處於快取狀態時,將上下文註冊的廣播放入佇列。 當應用程式離開快取狀態,例如回到前景時,系統會傳送所有排隊的廣播。 某些廣播的多個實例可能會合併成一個廣播。 截至Build.VERSION_CODES年。ICE_CREAM_SANDWICH,使用此方法註冊的接收器會正確遵守廣播意圖所指定的 Intent.setPackage(字串)。 在此之前,這份郵件會被忽略,並送達所有匹配的註冊收件人。 使用這些資料時要小心。 參數接收器 BroadcastReceiver:此值可能為空值。

(繼承來源 ContextWrapper)
RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler, ReceiverFlags)

註冊以接收意圖廣播,以便在排程器情境下執行。 更多資訊請參見 registerReceiver(BroadcastReceiver,IntentFilter,整數)與 registerReceiver(BroadcastReceiver,IntentFilter,String,Handler)。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。 截至Build.VERSION_CODES年。UPSIDE_DOWN_CAKE ,系統可在應用程式處於快取狀態時,將上下文註冊的廣播放入佇列。 當應用程式離開快取狀態,例如回到前景時,系統會傳送所有排隊的廣播。 某些廣播的多個實例可能會合併成一個廣播。 截至Build.VERSION_CODES年。ICE_CREAM_SANDWICH,使用此方法註冊的接收器會正確遵守廣播意圖所指定的 Intent.setPackage(字串)。 在此之前,這份郵件會被忽略,並送達所有匹配的註冊收件人。 使用這些資料時要小心。 參數接收器 BroadcastReceiver:負責處理廣播的 BroadcastReceiver。

(繼承來源 Context)
RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler)

註冊以接收意圖廣播,並在 var<排程器>/var< 的情境>下執行。

(繼承來源 ContextWrapper)
RegisterReceiver(BroadcastReceiver, IntentFilter)

註冊一個廣播接收器(BroadcastReceiver)以便在主活動執行緒中執行。

(繼承來源 ContextWrapper)
RemoveStickyBroadcast(Intent)
已淘汰.
(繼承來源 ContextWrapper)
RemoveStickyBroadcastAsUser(Intent, UserHandle)
已淘汰.
(繼承來源 ContextWrapper)
RevokeSelfPermissionOnKill(String)

觸發執行時權限的非同步撤銷。

(繼承來源 Context)
RevokeSelfPermissionsOnKill(ICollection<String>)

會觸發撤銷呼叫套件一個或多個權限。

(繼承來源 Context)
RevokeUriPermission(String, Uri, ActivityFlags)

移除先前以 grantUriPermission(String, Uri, int) 為特定目標套件新增的存取特定內容提供者 Uri 的權限。 給定的 Uri 會匹配所有先前獲得且相同或屬於該 Uri 子路徑的 Uri。 也就是說,撤銷「content://foo/target」會同時撤銷「content://foo/target」和「content://foo/target/sub」,但不會撤銷「content://foo」。 它不會移除任何存在於更高層級的前綴補助金。 與 revokeUriPermission(Uri,int) 不同,此方法僅會撤銷透過 grantUriPermission(String, Uri, int) 明確授予的權限,且僅限於指定的套件。 任何透過其他機制(剪貼簿、活動啟動、服務啟動等)達成的配對補助金都不會被移除。

(繼承來源 ContextWrapper)
RevokeUriPermission(Uri, ActivityFlags)

移除先前在 中新增的所有存取特定內容提供者 Uri 的權限。

(繼承來源 ContextWrapper)
SendBroadcast(Intent, String, Bundle)

將該意圖廣播給所有有興趣的廣播接收器,並允許執行可選的必要許可。

(繼承來源 Context)
SendBroadcast(Intent, String)

將該意圖廣播給所有有興趣的廣播接收器,並允許執行可選的必要許可。

(繼承來源 ContextWrapper)
SendBroadcast(Intent)

將該意圖廣播給所有有興趣的廣播接收器。

(繼承來源 ContextWrapper)
SendBroadcastAsUser(Intent, UserHandle, String)

那個版本 SendBroadcast(Intent, String) 允許你指定廣播要傳送給哪個使用者。

(繼承來源 ContextWrapper)
SendBroadcastAsUser(Intent, UserHandle)

那個版本 SendBroadcast(Intent) 允許你指定廣播要傳送給哪個使用者。

(繼承來源 ContextWrapper)
SendBroadcastWithMultiplePermissions(Intent, String[])

將該意圖廣播給所有有興趣的廣播接收器,允許執行一系列必要的權限。

(繼承來源 Context)
SendOrderedBroadcast(Intent, Int32, String, String, BroadcastReceiver, Handler, String, Bundle, Bundle)

依序向有興趣的接收者廣播意圖。

(繼承來源 ContextWrapper)
SendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, Result, String, Bundle)

那個版本 SendBroadcast(Intent) 允許你從廣播中接收回來的資料。

(繼承來源 ContextWrapper)
SendOrderedBroadcast(Intent, String, Bundle, BroadcastReceiver, Handler, Result, String, Bundle)

那個版本 #sendBroadcast(Intent) 允許你從廣播中接收回來的資料。

(繼承來源 Context)
SendOrderedBroadcast(Intent, String, Bundle)

將所定意圖廣播給所有有興趣的廣播接收器,一次一個傳送,讓更多優先接收者先消化該廣播,然後再傳送給較不偏好的接收器。

(繼承來源 Context)
SendOrderedBroadcast(Intent, String, String, BroadcastReceiver, Handler, Result, String, Bundle)

那個版本 #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 允許你指定應用程式操作,來強制限制廣播將傳送到哪些接收器。

(繼承來源 Context)
SendOrderedBroadcast(Intent, String)

將所定意圖廣播給所有有興趣的廣播接收器,一次一個傳送,讓更多優先接收者先消化該廣播,然後再傳送給較不偏好的接收器。 此呼叫為非同步;它會立即回傳,並在接收器運行時繼續執行。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。

(繼承來源 ContextWrapper)
SendOrderedBroadcastAsUser(Intent, UserHandle, String, BroadcastReceiver, Handler, Result, String, Bundle)

sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) 的版本,允許你指定廣播將傳送給哪個使用者。 此功能不適用於未預先安裝於系統映像中的應用程式。 欲了解更多意圖廣播資訊,請參閱 BroadcastReceiver。 需要 Android。Manifest.permission.INTERACT_ACROSS_USERS

(繼承來源 ContextWrapper)
SendStickyBroadcast(Intent, Bundle)

執行 #sendBroadcast(Intent) 一個「黏性」的行為,意即你傳送的意圖會在廣播完成後仍保留,讓其他人能透過回傳值 #registerReceiver(BroadcastReceiver, IntentFilter)快速取得該資料。

(繼承來源 Context)
SendStickyBroadcast(Intent)
已淘汰.

執行 #sendBroadcast(Intent) 一個「黏性」的行為,意即你傳送的意圖會在廣播完成後仍保留,讓其他人能透過回傳值 #registerReceiver(BroadcastReceiver, IntentFilter)快速取得該資料。

(繼承來源 ContextWrapper)
SendStickyBroadcastAsUser(Intent, UserHandle)
已淘汰.
(繼承來源 ContextWrapper)
SendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, Result, String, Bundle)
已淘汰.
(繼承來源 ContextWrapper)
SendStickyOrderedBroadcastAsUser(Intent, UserHandle, BroadcastReceiver, Handler, Result, String, Bundle)
已淘汰.
(繼承來源 ContextWrapper)
SetForeground(Boolean)

此會員已被棄用。

SetHandle(IntPtr, JniHandleOwnership)

設定 Handle 屬性。

(繼承來源 Object)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
SetTheme(Int32)

為這個情境設定基本主題。

(繼承來源 ContextWrapper)
SetWallpaper(Bitmap)
已淘汰.
(繼承來源 ContextWrapper)
SetWallpaper(Stream)
已淘汰.
(繼承來源 ContextWrapper)
ShouldShowRequestPermissionRationale(String)

判斷你是否應該在申請許可前先展示 UI。

(繼承來源 Context)
StartActivities(Intent[], Bundle)

啟動多項新活動。

(繼承來源 ContextWrapper)
StartActivities(Intent[])

就像 StartActivities(Intent[], Bundle) 沒有指定選項一樣。

(繼承來源 ContextWrapper)
StartActivity(Intent, Bundle)

啟動一項新活動。

(繼承來源 ContextWrapper)
StartActivity(Intent)

就像 StartActivity(Intent, Bundle) 沒有指定選項一樣。

(繼承來源 ContextWrapper)
StartActivity(Type)

跟 startActivity(Intent, Bundle) 一樣,但沒有指定選項。

(繼承來源 Context)
StartForeground(Int32, Notification, ForegroundService)

具有其他 foregroundServiceType 參數的多載版本 #startForeground(int, Notification)

StartForeground(Int32, Notification)

如果您的服務已啟動(執行中 Context#startService(Intent)),則也會讓此服務在前景執行,並在處於此狀態時提供要向使用者顯示的進行中通知。

StartForegroundService(Intent)

類似於 startService(Intent) ,但隱含承諾服務一旦開始執行就會呼叫 startForeground(int, android.app.Notification)。 服務會獲得相當於 ANR 間隔的時間來完成此事,否則系統會自動當機,屆時執行 SDK 版本 Build.VERSION_CODES 的裝置會記錄內部異常 ForegroundServiceDidNotStartInTimeException。S或更晚。 在較舊的 Android 版本中,會記錄一個內部例外 RemoteServiceException,並附有相應訊息。 與一般的 startService(Intent) 不同,此方法可隨時使用,無論服務的應用程式是否處於前景狀態。 注意:從 SDK 版本 Build.VERSION_CODES 開始。S,針對 SDK 版本 Build.VERSION_CODES 的應用程式。S 級以上的用戶不得從背景啟動前景服務。 詳情請參見行為變更:針對 Android 12 的應用程式。

(繼承來源 ContextWrapper)
StartInstrumentation(ComponentName, String, Bundle)

開始執行一個 Instrumentation 類別。

(繼承來源 ContextWrapper)
StartIntentSender(IntentSender, Intent, ActivityFlags, ActivityFlags, Int32, Bundle)

StartActivity(Intent, Bundle)是,但一開始就用一個意圖發送者。

(繼承來源 ContextWrapper)
StartIntentSender(IntentSender, Intent, ActivityFlags, ActivityFlags, Int32)

與 startIntentSender(IntentSender, Intent, int, int, int, Bundle) 相同,但未指定任何選項。

(繼承來源 ContextWrapper)
StartService(Intent)

請求啟動某項應用程式服務。

(繼承來源 ContextWrapper)
StopForeground(Boolean)

舊版 的 #stopForeground(int)

StopForeground(StopForegroundFlags)

將此服務從前景狀態移除,若需要更多記憶體,便可終止。

StopSelf()

如果服務已經開始,請停止。

StopSelf(Int32)

舊版 #stopSelfResult 不會傳回結果。

StopSelfResult(Int32)

如果最近啟動的時間是 <var>startId</var>,請停止服務。

StopService(Intent)

請求停止某項應用程式服務。

(繼承來源 ContextWrapper)
ToArray<T>()

從這個 Java 陣列包裝器建立一個受管理陣列。

(繼承來源 Object)
ToString()

回傳物件的字串表示。

(繼承來源 Object)
UnbindService(IServiceConnection)

斷開應用程式服務。

(繼承來源 ContextWrapper)
UnregisterComponentCallbacks(IComponentCallbacks)

移除 ComponentCallbacks 先前註冊於 #registerComponentCallbacks(ComponentCallbacks)的物件。

(繼承來源 Context)
UnregisterDeviceIdChangeListener(IIntConsumer)

移除一個裝置 ID,變更了 Context 中的監聽者。

(繼承來源 Context)
UnregisterFromRuntime()

將此 Java 節點從互通執行時中取消註冊。

(繼承來源 Object)
UnregisterReceiver(BroadcastReceiver)

取消註冊先前註冊的廣播接收器。

(繼承來源 ContextWrapper)
UpdateServiceBindings(ICollection<Context.UpdateBindingParams>)

對現有綁定進行批次更新。

(繼承來源 Context)
UpdateServiceGroup(IServiceConnection, Int32, Int32)

對於先前綁定於 #bindService 或相關方法的服務,改變系統管理該服務程序與其他程序之間的方式。

(繼承來源 Context)
Wait()

導致目前執行緒等待被喚醒,通常是透過 <em>通知</><em 或 em>中斷</em> 來喚醒。

(繼承來源 Object)
Wait(Int64, Int32)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)
Wait(Int64)

會讓目前執行緒等待喚醒,通常是透過 <em>通知</><em 或 em>中斷</em>,或是經過一定的真實時間。

(繼承來源 Object)

明確介面實作

名稱 Description
IJavaPeerable.Disposed()

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.Finalized()

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

(繼承來源 JavaObject)
IJavaPeerable.UnregisterFromRuntime()

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

擴充方法

名稱 Description
GetJniTypeName(IJavaPeerable)

取得實例 self類型的 JNI 名稱。

JavaAs<TResult>(IJavaPeerable)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

JavaCast<TResult>(IJavaObject)

執行 Android 執行時檢查型別轉換。

JavaCast<TResult>(IJavaObject)

服務是一個應用程式元件,代表應用程式希望在不與使用者互動的情況下執行較長時間的操作,或是提供其他應用程式使用的功能。

TryJavaCast<TResult>(IJavaPeerable, TResult)

試著強制self輸入 TResult,檢查 強制在 Java 端是否有效。

適用於