Struct droid_wrap::android::content::ContextWrapper

source ·
pub struct ContextWrapper { /* private fields */ }
Expand description

Context 的代理实现,它只是将其所有调用委托给另一个 Context。可以创建子类来修改行为,而无需更改原始 Context。

Implementations§

source§

impl ContextWrapper

source

pub fn get_class_loader(&self) -> ClassLoader

返回可用于查询此包中的类的类加载器。

source

pub fn send_broadcast(&self, intent: &Intent)

将给定的意图广播给所有感兴趣的 BroadcastReceiver。此调用是异步的;它会立即返回,您将在接收器运行时继续执行。接收器不会传播任何结果,接收器也无法中止广播。如果您想允许接收器传播结果或中止广播,则必须使用 sendOrderedBroadcast(Intent, String) 发送有序广播。有关 Intent 广播的更多信息,请参阅 BroadcastReceiver。 intent 要广播的 Intent;与此 Intent 匹配的所有接收器都将收到广播。

Methods from Deref<Target = Context>§

source

pub const MODE_PRIVATE: i32 = 0i32

source

pub const MODE_WORLD_READABLE: i32 = 1i32

source

pub const MODE_WORLD_WRITEABLE: i32 = 2i32

source

pub const MODE_APPEND: i32 = 32_768i32

source

pub const MODE_MULTI_PROCESS: i32 = 4i32

source

pub const MODE_ENABLE_WRITE_AHEAD_LOGGING: i32 = 8i32

source

pub const MODE_NO_LOCALIZED_COLLATORS: i32 = 16i32

source

pub const POWER_SERVICE: &'static str = "power"

source

pub const POWER_STATS_SERVICE: &'static str = "powerstats"

source

pub const RECOVERY_SERVICE: &'static str = "recovery"

source

pub const SYSTEM_UPDATE_SERVICE: &'static str = "system_update"

source

pub const WINDOW_SERVICE: &'static str = "window"

source

pub const LAYOUT_INFLATER_SERVICE: &'static str = "layout_inflater"

source

pub const ACCOUNT_SERVICE: &'static str = "account"

source

pub const ACTIVITY_SERVICE: &'static str = "activity"

source

pub const ACTIVITY_TASK_SERVICE: &'static str = "activity_task"

source

pub const URI_GRANTS_SERVICE: &'static str = "uri_grants"

source

pub const ALARM_SERVICE: &'static str = "alarm"

source

pub const NOTIFICATION_SERVICE: &'static str = "notification"

source

pub const ACCESSIBILITY_SERVICE: &'static str = "accessibility"

source

pub const CAPTIONING_SERVICE: &'static str = "captioning"

source

pub const KEYGUARD_SERVICE: &'static str = "keyguard"

source

pub const LOCATION_SERVICE: &'static str = "location"

source

pub const COUNTRY_DETECTOR: &'static str = "country_detector"

source

pub const SEARCH_SERVICE: &'static str = "search"

source

pub const SENSOR_SERVICE: &'static str = "sensor"

source

pub const SENSOR_PRIVACY_SERVICE: &'static str = "sensor_privacy"

source

pub const STORAGE_SERVICE: &'static str = "storage"

source

pub const STORAGE_STATS_SERVICE: &'static str = "storagestats"

source

pub const WALLPAPER_SERVICE: &'static str = "wallpaper"

source

pub const VIBRATOR_MANAGER_SERVICE: &'static str = "vibrator_manager"

source

pub const VIBRATOR_SERVICE: &'static str = "vibrator"

source

pub const STATUS_BAR_SERVICE: &'static str = "statusbar"

source

pub const CONNECTIVITY_SERVICE: &'static str = "connectivity"

source

pub const PAC_PROXY_SERVICE: &'static str = "pac_proxy"

source

pub const VCN_MANAGEMENT_SERVICE: &'static str = "vcn_management"

source

pub const NETD_SERVICE: &'static str = "netd"

source

pub const NETWORK_STACK_SERVICE: &'static str = "network_stack"

source

pub const TETHERING_SERVICE: &'static str = "tethering"

source

pub const IPSEC_SERVICE: &'static str = "ipsec"

source

pub const VPN_MANAGEMENT_SERVICE: &'static str = "vpn_management"

source

pub const CONNECTIVITY_DIAGNOSTICS_SERVICE: &'static str = "connectivity_diagnostics"

source

pub const TEST_NETWORK_SERVICE: &'static str = "test_network"

source

pub const UPDATE_LOCK_SERVICE: &'static str = "updatelock"

source

pub const NETWORKMANAGEMENT_SERVICE: &'static str = "network_management"

source

pub const SLICE_SERVICE: &'static str = "slice"

source

pub const NETWORK_STATS_SERVICE: &'static str = "netstats"

source

pub const WIFI_SERVICE: &'static str = "wifi"

source

pub const WIFI_NL80211_SERVICE: &'static str = "wifinl80211"

source

pub const WIFI_P2P_SERVICE: &'static str = "wifip2p"

source

pub const WIFI_AWARE_SERVICE: &'static str = "wifiaware"

source

pub const WIFI_SCANNING_SERVICE: &'static str = "wifiscanner"

source

pub const WIFI_RTT_SERVICE: &'static str = "rttmanager"

source

pub const WIFI_RTT_RANGING_SERVICE: &'static str = "wifirtt"

source

pub const LOWPAN_SERVICE: &'static str = "lowpan"

source

pub const ETHERNET_SERVICE: &'static str = "ethernet"

source

pub const NSD_SERVICE: &'static str = "servicediscovery"

source

pub const AUDIO_SERVICE: &'static str = "audio"

source

pub const AUDIO_DEVICE_VOLUME_SERVICE: &'static str = "audio_device_volume"

source

pub const MEDIA_TRANSCODING_SERVICE: &'static str = "media_transcoding"

source

pub const AUTH_SERVICE: &'static str = "auth"

source

pub const FINGERPRINT_SERVICE: &'static str = "fingerprint"

source

pub const FACE_SERVICE: &'static str = "face"

source

pub const IRIS_SERVICE: &'static str = "iris"

source

pub const BIOMETRIC_SERVICE: &'static str = "biometric"

source

pub const MEDIA_COMMUNICATION_SERVICE: &'static str = "media_communication"

source

pub const MEDIA_ROUTER_SERVICE: &'static str = "media_router"

source

pub const MEDIA_SESSION_SERVICE: &'static str = "media_session"

source

pub const TELEPHONY_SERVICE: &'static str = "phone"

source

pub const TELEPHONY_SUBSCRIPTION_SERVICE: &'static str = "telephony_subscription_service"

source

pub const TELECOM_SERVICE: &'static str = "telecom"

source

pub const CARRIER_CONFIG_SERVICE: &'static str = "carrier_config"

source

pub const EUICC_SERVICE: &'static str = "euicc"

source

pub const EUICC_CARD_SERVICE: &'static str = "euicc_card"

source

pub const MMS_SERVICE: &'static str = "mms"

source

pub const CLIPBOARD_SERVICE: &'static str = "clipboard"

source

pub const TEXT_CLASSIFICATION_SERVICE: &'static str = "textclassification"

source

pub const SELECTION_TOOLBAR_SERVICE: &'static str = "selection_toolbar"

source

pub const FONT_SERVICE: &'static str = "font"

source

pub const ATTENTION_SERVICE: &'static str = "attention"

source

pub const ROTATION_RESOLVER_SERVICE: &'static str = "resolver"

source

pub const INPUT_METHOD_SERVICE: &'static str = "input_method"

source

pub const TEXT_SERVICES_MANAGER_SERVICE: &'static str = "textservices"

source

pub const APPWIDGET_SERVICE: &'static str = "appwidget"

source

pub const VOICE_INTERACTION_MANAGER_SERVICE: &'static str = "voiceinteraction"

source

pub const AUTOFILL_MANAGER_SERVICE: &'static str = "autofill"

source

pub const TEXT_TO_SPEECH_MANAGER_SERVICE: &'static str = "texttospeech"

source

pub const CONTENT_CAPTURE_MANAGER_SERVICE: &'static str = "content_capture"

source

pub const TRANSLATION_MANAGER_SERVICE: &'static str = "translation"

source

pub const UI_TRANSLATION_SERVICE: &'static str = "ui_translation"

source

pub const CONTENT_SUGGESTIONS_SERVICE: &'static str = "content_suggestions"

source

pub const APP_PREDICTION_SERVICE: &'static str = "app_prediction"

source

pub const SEARCH_UI_SERVICE: &'static str = "search_ui"

source

pub const SMARTSPACE_SERVICE: &'static str = "smartspace"

source

pub const CLOUDSEARCH_SERVICE: &'static str = "cloudsearch"

source

pub const SOUND_TRIGGER_SERVICE: &'static str = "soundtrigger"

source

pub const SOUND_TRIGGER_MIDDLEWARE_SERVICE: &'static str = "soundtrigger_middleware"

source

pub const WALLPAPER_EFFECTS_GENERATION_SERVICE: &'static str = "wallpaper_effects_generation"

source

pub const MUSIC_RECOGNITION_SERVICE: &'static str = "music_recognition"

source

pub const PERMISSION_SERVICE: &'static str = "permission"

source

pub const LEGACY_PERMISSION_SERVICE: &'static str = "legacy_permission"

source

pub const PERMISSION_CONTROLLER_SERVICE: &'static str = "permission_controller"

source

pub const PERMISSION_CHECKER_SERVICE: &'static str = "permission_checker"

source

pub const PERMISSION_ENFORCER_SERVICE: &'static str = "permission_enforcer"

source

pub const APP_HIBERNATION_SERVICE: &'static str = "app_hibernation"

source

pub const BACKUP_SERVICE: &'static str = "backup"

source

pub const ROLLBACK_SERVICE: &'static str = "rollback"

source

pub const REBOOT_READINESS_SERVICE: &'static str = "reboot_readiness"

source

pub const DROPBOX_SERVICE: &'static str = "dropbox"

source

pub const BACKGROUND_INSTALL_CONTROL_SERVICE: &'static str = "background_install_control"

source

pub const BINARY_TRANSPARENCY_SERVICE: &'static str = "transparency"

source

pub const DEVICE_IDLE_CONTROLLER: &'static str = "deviceidle"

source

pub const POWER_WHITELIST_MANAGER: &'static str = "power_whitelist"

source

pub const POWER_EXEMPTION_SERVICE: &'static str = "power_exemption"

source

pub const DEVICE_POLICY_SERVICE: &'static str = "device_policy"

source

pub const UI_MODE_SERVICE: &'static str = "uimode"

source

pub const DOWNLOAD_SERVICE: &'static str = "download"

source

pub const BATTERY_SERVICE: &'static str = "batterymanager"

source

pub const NFC_SERVICE: &'static str = "nfc"

source

pub const BLUETOOTH_SERVICE: &'static str = "bluetooth"

source

pub const SIP_SERVICE: &'static str = "sip"

source

pub const USB_SERVICE: &'static str = "usb"

source

pub const ADB_SERVICE: &'static str = "adb"

source

pub const SERIAL_SERVICE: &'static str = "serial"

source

pub const HDMI_CONTROL_SERVICE: &'static str = "hdmi_control"

source

pub const INPUT_SERVICE: &'static str = "input"

source

pub const DISPLAY_SERVICE: &'static str = "display"

source

pub const COLOR_DISPLAY_SERVICE: &'static str = "color_display"

source

pub const USER_SERVICE: &'static str = "user"

source

pub const LAUNCHER_APPS_SERVICE: &'static str = "launcherapps"

source

pub const RESTRICTIONS_SERVICE: &'static str = "restrictions"

source

pub const APP_OPS_SERVICE: &'static str = "appops"

source

pub const ROLE_SERVICE: &'static str = "role"

source

pub const CAMERA_SERVICE: &'static str = "camera"

source

pub const PRINT_SERVICE: &'static str = "print"

source

pub const COMPANION_DEVICE_SERVICE: &'static str = "companiondevice"

source

pub const VIRTUAL_DEVICE_SERVICE: &'static str = "virtualdevice"

source

pub const CONSUMER_IR_SERVICE: &'static str = "consumer_ir"

source

pub const TRUST_SERVICE: &'static str = "trust"

source

pub const TV_INTERACTIVE_APP_SERVICE: &'static str = "tv_interactive_app"

source

pub const TV_INPUT_SERVICE: &'static str = "tv_input"

source

pub const TV_TUNER_RESOURCE_MGR_SERVICE: &'static str = "tv_tuner_resource_mgr"

source

pub const NETWORK_SCORE_SERVICE: &'static str = "network_score"

source

pub const USAGE_STATS_SERVICE: &'static str = "usagestats"

source

pub const JOB_SCHEDULER_SERVICE: &'static str = "jobscheduler"

source

pub const RESOURCE_ECONOMY_SERVICE: &'static str = "tare"

source

pub const PERSISTENT_DATA_BLOCK_SERVICE: &'static str = "persistent_data_block"

source

pub const OEM_LOCK_SERVICE: &'static str = "oem_lock"

source

pub const MEDIA_PROJECTION_SERVICE: &'static str = "media_projection"

source

pub const MIDI_SERVICE: &'static str = "midi"

source

pub const RADIO_SERVICE: &'static str = "broadcastradio"

source

pub const HARDWARE_PROPERTIES_SERVICE: &'static str = "hardware_properties"

source

pub const THERMAL_SERVICE: &'static str = "thermalservice"

source

pub const PERFORMANCE_HINT_SERVICE: &'static str = "performance_hint"

source

pub const SHORTCUT_SERVICE: &'static str = "shortcut"

source

pub const CONTEXTHUB_SERVICE: &'static str = "contexthub"

source

pub const SYSTEM_HEALTH_SERVICE: &'static str = "systemhealth"

source

pub const GATEKEEPER_SERVICE: &'static str = "android.service.gatekeeper.IGateKeeperService"

source

pub const DEVICE_IDENTIFIERS_SERVICE: &'static str = "device_identifiers"

source

pub const INCIDENT_SERVICE: &'static str = "incident"

source

pub const INCIDENT_COMPANION_SERVICE: &'static str = "incidentcompanion"

source

pub const STATS_MANAGER_SERVICE: &'static str = "statsmanager"

source

pub const STATS_COMPANION_SERVICE: &'static str = "statscompanion"

source

pub const STATS_BOOTSTRAP_ATOM_SERVICE: &'static str = "statsbootstrap"

source

pub const STATS_MANAGER: &'static str = "stats"

source

pub const PLATFORM_COMPAT_SERVICE: &'static str = "platform_compat"

source

pub const PLATFORM_COMPAT_NATIVE_SERVICE: &'static str = "platform_compat_native"

source

pub const BUGREPORT_SERVICE: &'static str = "bugreport"

source

pub const OVERLAY_SERVICE: &'static str = "overlay"

source

pub const RESOURCES_SERVICE: &'static str = "resources"

source

pub const IDMAP_SERVICE: &'static str = "idmap"

source

pub const VR_SERVICE: &'static str = "vrmanager"

source

pub const CROSS_PROFILE_APPS_SERVICE: &'static str = "crossprofileapps"

source

pub const SECURE_ELEMENT_SERVICE: &'static str = "secure_element"

source

pub const TIME_DETECTOR_SERVICE: &'static str = "time_detector"

source

pub const TIME_ZONE_DETECTOR_SERVICE: &'static str = "time_zone_detector"

source

pub const TIME_MANAGER_SERVICE: &'static str = "time_manager"

source

pub const APP_BINDING_SERVICE: &'static str = "app_binding"

source

pub const TELEPHONY_IMS_SERVICE: &'static str = "telephony_ims"

source

pub const SYSTEM_CONFIG_SERVICE: &'static str = "system_config"

source

pub const TELEPHONY_RCS_MESSAGE_SERVICE: &'static str = "ircsmessage"

source

pub const DYNAMIC_SYSTEM_SERVICE: &'static str = "dynamic_system"

source

pub const BLOB_STORE_SERVICE: &'static str = "blob_store"

source

pub const TELEPHONY_REGISTRY_SERVICE: &'static str = "telephony_registry"

source

pub const BATTERY_STATS_SERVICE: &'static str = "batterystats"

source

pub const APP_SEARCH_SERVICE: &'static str = "app_search"

source

pub const APP_INTEGRITY_SERVICE: &'static str = "app_integrity"

source

pub const DATA_LOADER_MANAGER_SERVICE: &'static str = "dataloader_manager"

source

pub const INCREMENTAL_SERVICE: &'static str = "incremental"

source

pub const ATTESTATION_VERIFICATION_SERVICE: &'static str = "attestation_verification"

source

pub const FILE_INTEGRITY_SERVICE: &'static str = "file_integrity"

source

pub const REMOTE_PROVISIONING_SERVICE: &'static str = "remote_provisioning"

source

pub const LIGHTS_SERVICE: &'static str = "lights"

source

pub const UWB_SERVICE: &'static str = "uwb"

source

pub const DREAM_SERVICE: &'static str = "dream"

source

pub const SMS_SERVICE: &'static str = "sms"

source

pub const PEOPLE_SERVICE: &'static str = "people"

source

pub const DEVICE_STATE_SERVICE: &'static str = "device_state"

source

pub const MEDIA_METRICS_SERVICE: &'static str = "media_metrics"

source

pub const SPEECH_RECOGNITION_SERVICE: &'static str = "speech_recognition"

source

pub const GAME_SERVICE: &'static str = "game"

source

pub const DOMAIN_VERIFICATION_SERVICE: &'static str = "domain_verification"

source

pub const DISPLAY_HASH_SERVICE: &'static str = "display_hash"

source

pub const LOCALE_SERVICE: &'static str = "locale"

source

pub const SAFETY_CENTER_SERVICE: &'static str = "safety_center"

source

pub const NEARBY_SERVICE: &'static str = "nearby"

source

pub const AMBIENT_CONTEXT_SERVICE: &'static str = "ambient_context"

source

pub const WEARABLE_SENSING_SERVICE: &'static str = "wearable_sensing"

source

pub const HEALTHCONNECT_SERVICE: &'static str = "healthconnect"

source

pub const CREDENTIAL_SERVICE: &'static str = "credential"

source

pub const DEVICE_LOCK_SERVICE: &'static str = "device_lock"

source

pub const VIRTUALIZATION_SERVICE: &'static str = "virtualization"

source

pub const GRAMMATICAL_INFLECTION_SERVICE: &'static str = "grammatical_inflection"

source

pub const SATELLITE_SERVICE: &'static str = "satellite"

source

pub const SHARED_CONNECTIVITY_SERVICE: &'static str = "shared_connectivity"

source

pub fn get_class_loader(&self) -> ClassLoader

返回可用于查询此包中的类的类加载器。

source

pub fn send_broadcast(&self, intent: &Intent)

将给定的意图广播给所有感兴趣的 BroadcastReceiver。此调用是异步的;它会立即返回,您将在接收器运行时继续执行。接收器不会传播任何结果,接收器也无法中止广播。如果您想允许接收器传播结果或中止广播,则必须使用 sendOrderedBroadcast(Intent, String) 发送有序广播。有关 Intent 广播的更多信息,请参阅 BroadcastReceiver。 intent 要广播的 Intent;与此 Intent 匹配的所有接收器都将收到广播。

source

pub fn start_activity(&self, intent: &Intent)

与 startActivity(Intent, Bundle) 相同,但未指定任何选项。 intent 要启动的活动的描述。 抛出:ActivityNotFoundException – `

source

pub fn get_package_name(&self) -> String

返回此应用程序包的名称。

source

pub fn get_base_package_name(&self) -> String

返回此上下文所派生自的基础上下文的名称。这与 getOpPackageName() 相同,除非系统组件加载到其他应用进程中,在这种情况下 getOpPackageName() 将是该进程中主软件包的名称(以便应用操作 uid 验证可以使用该名称)。

source

pub fn get_op_package_name(&self) -> String

返回应用于此上下文中的 android.app.AppOpsManager 调用的包名称,以便 app ops manager 的 uid 验证可以使用该名称。这通常不适用于第三方应用程序开发人员。

source

pub fn get_attribution_tag(&self) -> Option<String>

归因可用于复杂的应用中,以在逻辑上区分应用的各个部分。例如,博客应用可能还内置有即时通讯应用。在这种情况下,每个子功能可以使用两个单独的标签。 返回:此上下文所针对的归因标签,如果这是默认标签,则返回 null。

source

pub fn get_package_resource_path(&self) -> String

返回此上下文的主要 Android 包的完整路径。Android 包是一个 ZIP 文件,其中包含应用程序的主要资源。注意:这通常对应用程序没有用,因为它们不应直接访问文件系统。 返回:String 资源路径。

source

pub fn get_package_code_path(&self) -> String

返回此上下文的主要 Android 包的完整路径。Android 包是一个 ZIP 文件,其中包含应用程序的主要代码和资产。 注意:这通常对应用程序没有用,因为它们不应直接访问文件系统。 返回:String 代码和资产的路径。

source

pub fn get_system_service(&self, name: String) -> Option<Object>

按名称返回系统级服务的句柄。返回对象的类因请求的名称而异。当前可用的名称为: WINDOW_SERVICE (“window”) 您可以在顶级窗口管理器中放置自定义窗口。返回的对象是 WindowManager。只能从可视上下文(例如 Activity 或使用 createWindowContext(int, Bundle) 创建的上下文)中获取,这些上下文会根据屏幕区域的配置和可视边界进行调整。 LAYOUT_INFLATER_SERVICE (“layout_inflater”) android.view.LayoutInflater 用于在此上下文中填充布局资源。只能从可视上下文(例如 Activity 或使用 createWindowContext(int, Bundle) 创建的上下文)获取,这些上下文会根据屏幕区域的配置和可视边界进行调整。 ACTIVITY_SERVICE (“activity”) 用于与系统全局活动状态交互的 ActivityManager。 WALLPAPER_SERVICE (“wallpaper”) android.service.wallpaper.WallpaperService 用于在此上下文中访问壁纸。只能从可视上下文(例如 Activity 或使用 createWindowContext(int, Bundle) 创建的上下文)获取,这些上下文会根据屏幕区域的配置和可视边界进行调整。 POWER_SERVICE (“power”) 一个用于控制电源管理的android.os.PowerManager。 ALARM_SERVICE (“alarm”) 一个 Android 应用程序 AlarmManager,用于在您选择的时间接收意图。 NOTIFICATION_SERVICE (“notification”) android.app.NotificationManager,用于通知用户后台事件。 KEYGUARD_SERVICE (“keyguard”) 一个用于控制键盘锁的 android.app.KeyguardManager。 LOCATION_SERVICE (“location”) android.location.LocationManager 用于控制位置(例如 GPS)更新。 SEARCH_SERVICE (“search”) 一个用于处理搜索的android.app.SearchManager。 VIBRATOR_MANAGER_SERVICE (“vibrator_manager”) android.os.VibratorManager,用于访问设备振动器、与各个振动器交互以及在多个振动器上播放同步效果。 VIBRATOR_SERVICE (“vibrator”) 一个android.os.Vibrator,用于与振动器硬件进行交互。 CONNECTIVITY_SERVICE (“connectivity”) 用于处理网络连接管理的 ConnectivityManager。 IPSEC_SERVICE (“ipsec”) IpSecManager 用于管理套接字和网络上的 IPSec。 WIFI_SERVICE (“wifi”) 用于管理 Wi-Fi 连接的 WifiManager。在 Android 7 之前的版本中,应仅从应用上下文中获取它,而不能从任何其他派生上下文中获取它,以避免调用过程中出现内存泄漏。 WIFI_AWARE_SERVICE (“wifiaware”) WifiAwareManager 用于管理 Wi-Fi Aware 发现和连接。 WIFI_P2P_SERVICE (“wifip2p”) WifiP2pManager 用于管理 Wi-Fi Direct 连接。 INPUT_METHOD_SERVICE (“input_method”) 用于管理输入方法的 InputMethodManager。 UI_MODE_SERVICE (“uimode”) 一个用于控制 UI 模式的 android.app.UiModeManager。 DOWNLOAD_SERVICE (“download”) 用于请求 HTTP 下载的 android.app.DownloadManager BATTERY_SERVICE (“batterymanager”) 用于管理电池状态的 android.os.BatteryManager JOB_SCHEDULER_SERVICE (“taskmanager”) 一个用于管理计划任务的android.app.job.JobScheduler NETWORK_STATS_SERVICE (“netstats”) 用于查询网络使用情况统计数据的 NetworkStatsManager。 HARDWARE_PROPERTIES_SERVICE (“hardware_properties”) 用于访问硬件属性的 android.os.HardwarePropertiesManager。 DOMAIN_VERIFICATION_SERVICE (“domain_verification”) android.content.pm.verify.domain.DomainVerificationManager,用于访问 Web 域批准状态。 DISPLAY_HASH_SERVICE (“display_hash”) android.view.displayhash.DisplayHashManager 用于管理显示哈希。 注意:通过此 API 获取的系统服务可能与获取它们的上下文密切相关。一般来说,不要在各种不同的上下文(活动、应用程序、服务、提供商等)之间共享服务对象。 注意:PackageManager.isInstantApp() 返回 true 的免安装应用无法访问以下系统服务:DEVICE_POLICY_SERVICE、FINGERPRINT_SERVICE、KEYGUARD_SERVICE、SHORTCUT_SERVICE、USB_SERVICE、WALLPAPER_SERVICE、WIFI_P2P_SERVICE、WIFI_SERVICE、WIFI_AWARE_SERVICE。对于这些服务,此方法将返回 null。通常,如果您以免安装应用的形式运行,则应始终检查此方法的结果是否为 null。 注意:在实现此方法时,请记住可以在较新的 Android 版本中添加新服务,因此如果您只是在寻找上面提到的明确名称,请确保在您无法识别该名称时返回 null — 如果您抛出 RuntimeException 异常,您的应用可能会在新的 Android 版本上中断。 返回:如果名称不存在则返回 null。 name 所需服务的名称。

source

pub fn move_shared_preferences_from( &self, source_context: &Self, name: String, ) -> bool

将现有的共享首选项文件从给定的源存储上下文移动到此上下文。这通常用于升级后在存储位置之间迁移数据,例如移至设备保护的存储。 返回:如果动作成功,或者如果在源上下文中不存在共享偏好,则为false。 source_context 包含现有共享首选项的源上下文。 name 共享首选项文件的名称。

source

pub fn delete_shared_preferences(&self, name: String) -> bool

删除现有的共享首选项文件。 返回:如果共享首选项文件已成功删除,则返回 true;否则返回 false。 name 共享首选项文件的名称(在应用程序包中是唯一的)。

source

pub fn delete_file(&self, name: String) -> bool

删除与此 Context 的应用程序包关联的给定私有文件。 返回:如果文件已成功删除,则返回 true;否则返回 false。 name 要删除的文件的名称;不能包含路径分隔符。

source

pub fn get_file_stream_path(&self, name: String) -> File

返回文件系统中存储使用 openFileOutput 创建的文件的绝对路径。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 返回:给定文件的绝对路径。 name 您想要获取其路径的文件的名称。

source

pub fn get_shared_preferences_path(&self, name: String) -> File

返回文件系统中存储使用 getSharedPreferences(String, int) 创建的文件的绝对路径。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 返回:给定文件的绝对路径。 name 您想要获取其路径的共享首选项的名称。

source

pub fn get_data_dir(&self) -> File

返回文件系统中存储此应用所有私有文件的目录的绝对路径。应用不应直接使用此路径;而应使用 getFilesDir()、getCacheDir()、getDir(String, int) 或此类上的其他存储 API。 如果调用应用移动到已采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。调用应用无需额外权限即可读取或写入返回路径下的文件。

source

pub fn get_files_dir(&self) -> File

返回文件系统中存储使用 openFileOutput 创建的文件的目录的绝对路径。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 调用应用程序无需额外权限即可读取或写入返回路径下的文件。保存应用程序文件的目录的路径。

source

pub fn get_crate_dir(&self, crate_id: String) -> File

返回与文件系统上的 crate 相关的目录的绝对路径。crate_id 需要经过验证的文件名。它不能包含任何“..”、“.”、File.separatorChar 等。 如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。调用应用程序无需额外权限即可读取或写入返回路径下的文件。 返回:crate 目录文件。 crate_id getDataDir()/ crates 下的经过验证的相对文件名

source

pub fn get_no_backup_files_dir(&self) -> File

返回文件系统上目录的绝对路径,类似于 getFilesDir()。不同之处在于,放置在此目录下的文件将被排除在自动备份到远程存储之外。 有关 Android 中自动备份机制的完整讨论,请参阅 BackupAgent。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 调用应用程序无需额外权限即可读取或写入返回路径下的文件。 返回:包含不会自动备份到远程存储的应用程序文件的目录的路径。

source

pub fn get_external_files_dir(&self, type: Option<String>) -> Option<File>

返回主共享/外部存储设备上目录的绝对路径,应用程序可在该目录中放置其拥有的持久文件。这些文件是应用程序内部的,通常不作为媒体对用户可见。 这与 getFilesDir() 类似,因为这些文件将在应用程序卸载时被删除,但存在一些重要区别:共享存储可能并非始终可用,因为用户可以弹出可移动媒体。可以使用 Environment.getExternalStorageState(File) 检查媒体状态。 这些文件没有强制执行安全性。例如,任何拥有 android.Manifest.permission.WRITE_EXTERNAL_STORAGE 的应用程序都可以写入这些文件。 如果共享存储设备是模拟的(由 Environment.isExternalStorageEmulated(File) 确定),则其内容由私有用户数据分区支持,这意味着将数据存储在此处而不是 getFilesDir() 返回的私有目录中几乎没有好处。 从 Build.VERSION_CODES.KITKAT开始,无需任何权限即可读取或写入返回的路径;调用应用程序始终可以访问它。这仅适用于为调用应用程序的软件包名称生成的路径。 要访问属于其他软件包的路径,需要 android.Manifest.permission.WRITE_EXTERNAL_STORAGE 和/或 android.Manifest.permission.READ_EXTERNAL_STORAGE。 在具有多个用户的设备上(如 UserManager 所述),每个用户都有自己独立的共享存储。应用程序只能访问他们以该用户身份运行的共享存储。 如果插入了不同的共享存储介质,则返回的路径可能会随时间而变化,因此只应保留相对路径。以下是操作应用程序共享存储中的文件的典型代码示例: @sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java private_file 如果您为此函数提供非空类型,则返回的文件将是指向给定类型的子目录的路径。虽然媒体扫描仪不会自动扫描这些文件,但您可以使用 MediaScannerConnection.scanFile 将它们明确添加到媒体数据库。 请注意,这与 Environment.getExternalStoragePublicDirectory() 不同,后者提供所有应用程序共享的媒体目录。此处返回的目录归应用程序所有,卸载应用程序时将删除其内容。 与 Environment.getExternalStoragePublicDirectory() 不同,此处返回的目录将自动为您创建。以下是操作应用程序共享存储中的图片并将其添加到媒体数据库的典型代码示例: @sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java private_picture 返回:应用程序特定目录的绝对路径。如果共享存储当前不可用,则可能返回 null。 type 要返回的文件目录的类型。对于文件目录的根目录,可能为 null;对于子目录,可能为以下常量之一: Environment.DIRECTORY_MUSIC、Environment.DIRECTORY_PODCASTS、Environment.DIRECTORY_RINGTONES、Environment.DIRECTORY_ALARMS、Environment.DIRECTORY_NOTIFICATIONS、Environment.DIRECTORY_PICTURES 或 Environment.DIRECTORY_MOVIES。

source

pub fn get_obb_dir(&self) -> Option<File>

返回可找到此应用程序的 OBB 文件(如果有)的主要共享/外部存储目录。请注意,如果应用程序没有任何 OBB 文件,则此目录可能不存在。 这与 getFilesDir() 类似,当应用程序卸载时这些文件将被删除,但也存在一些重要的区别: 共享存储可能并不总是可用,因为用户可以弹出可移动媒体。可以使用 Environment.getExternalStorageState(File) 检查媒体状态。 这些文件没有强制实施安全性。例如,任何持有 android.Manifest.permission.WRITE_EXTERNAL_STORAGE 的应用程序都可以写入这些文件。 从 Build.VERSION_CODES.KITKAT 开始,无需任何权限即可读取或写入此方法返回的路径。但是,从 Build.VERSION_CODES.M 开始,要读取 OBB 扩展文件,您必须在应用清单中声明 android.Manifest.permission.READ_EXTERNAL_STORAGE 权限,并在运行时请求权限,如下所示: <uses-permission android:name=“android.permission.READ_EXTERNAL_STORAGE” android:maxSdkVersion=“23” /> 从 Build.VERSION_CODES.N 开始,android.Manifest.permission.READ_EXTERNAL_STORAGE 权限不再需要,因此不要在运行时请求此权限。要处理这两种情况,您的应用必须先尝试读取 OBB 文件,如果失败,您必须在运行时请求 android.Manifest.permission.READ_EXTERNAL_STORAGE 权限。以下代码片段显示了如何执行此操作: File obb = new File(obb_filename); boolean open_failed = false; try { BufferedReader br = new BufferedReader(new FileReader(obb)); open_failed = false; ReadObbFile(br); } catch (IOException e) { open_failed = true; } if (open_failed) { // 读取 OBB 文件之前请求 READ_EXTERNAL_STORAGE 权限 ReadObbFileWithPermission(); } 在具有多个用户的设备上(如 UserManager 所述),多个用户可能共享同一个 OBB 存储位置。应用程序应确保在不同用户下运行的多个实例不会互相干扰。 返回:应用程序特定目录的绝对路径。如果共享存储当前不可用,则可能返回 null。

source

pub fn get_cache_dir(&self) -> File

返回文件系统上应用程序特定缓存目录的绝对路径。系统将自动删除此目录中的文件,因为设备上的其他地方需要磁盘空间。 系统将始终首先删除较旧的文件,如 File.lastModified() 所报告的。如果需要,您可以使用 StorageManager.setCacheBehaviorGroup(File, boolean) 和 StorageManager.setCacheBehaviorTombstone(File, boolean) 对文件的删除方式进行更多控制。 强烈建议应用程序将其缓存空间使用量保持在 StorageManager.getCacheQuotaBytes(java.util.UUID) 返回的配额以下。如果您的应用程序超出此配额,则在需要额外磁盘空间时,您的缓存文件将是第一批被删除的文件。 相反,如果您的应用程序保持在此配额以下,则在需要额外磁盘空间时,您的缓存文件将是最后被删除的文件。请注意,您的缓存配额将随着时间的推移而变化,具体取决于用户与您的应用程序交互的频率以及系统范围磁盘空间的使用量。 如果调用应用程序移至已采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。应用程序不需要额外的权限来读取或写入返回的路径,因为此路径位于其私有存储中。 返回:保存应用程序缓存文件的目录的路径。

source

pub fn get_code_cache_dir(&self) -> File

返回文件系统上用于存储缓存代码的应用程序特定缓存目录的绝对路径。当您的特定应用程序升级时以及整个平台升级时,系统都会删除存储在此位置的所有文件。 此位置最适合存储应用程序在运行时生成的编译或优化代码。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 应用程序不需要额外的权限来读取或写入返回的路径,因为此路径位于其私有存储中。 返回:保存应用程序代码缓存文件的目录的路径。

source

pub fn get_external_cache_dir(&self) -> Option<File>

返回主共享/外部存储设备上应用程序特定目录的绝对路径,应用程序可将其拥有的缓存文件放置在该目录中。这些文件是应用程序内部的,通常不会作为媒体对用户可见。 这与 getCacheDir() 类似,因为这些文件将在应用程序卸载时被删除,但存在一些重要区别:平台并不总是监控共享存储中的可用空间,因此可能不会自动删除这些文件。应用程序应始终管理此位置使用的最大空间。 目前,平台只会在 Build.VERSION_CODES.JELLY_BEAN_MR1 或更高版本上运行且 Environment.isExternalStorageEmulated(File) 返回 true 时删除此处的文件。共享存储可能并非始终可用,因为用户可以弹出可移动媒体。 可以使用 Environment.getExternalStorageState(File) 检查媒体状态。这些文件没有强制执行安全性。例如,任何拥有 android.Manifest.permission.WRITE_EXTERNAL_STORAGE的应用程序可以写入这些文件。 如果共享存储设备是模拟的(由 Environment.isExternalStorageEmulated(File) 确定),则其内容由私有用户数据分区支持,这意味着将数据存储在此处而不是 getCacheDir() 返回的私有目录中几乎没有好处。 从 Build.VERSION_CODES.KITKAT 开始,无需任何权限即可读取或写入返回的路径;调用应用程序始终可以访问它。这仅适用于为调用应用程序的软件包名称生成的路径。 要访问属于其他软件包的路径,需要 android.Manifest.permission.WRITE_EXTERNAL_STORAGE 和/或 android.Manifest.permission.READ_EXTERNAL_STORAGE。在具有多个用户的设备上(如 UserManager 所述),每个用户都有自己独立的共享存储。 应用程序只能访问他们以该用户身份运行的共享存储。如果插入不同的共享存储介质,则返回的路径可能会随时间而变化,因此只应保留相对路径。 返回:应用程序特定目录的绝对路径。如果共享存储当前不可用,则可能返回 null。

source

pub fn get_preloads_file_cache(&self) -> Option<File>

返回预加载缓存中应用程序特定目录的绝对路径。当设备存储空间不足时,可以删除存储在缓存目录中的文件。无法保证何时删除这些文件。

source

pub fn get_dir(&self, name: String, mode: i32) -> File

查询(如果需要)创建一个新目录,应用程序可以在其中放置其自己的自定义数据文件。您可以使用返回的 File 对象创建和访问此目录中的文件。 请注意,通过 File 对象创建的文件只能由您自己的应用程序访问;您只能设置整个目录的模式,而不能设置单个文件的模式。 如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。应用程序不需要额外的权限来读取或写入返回的路径,因为此路径位于其私有存储中。 返回:请求的目录的 File 对象。如果目录尚不存在,则将创建该目录。 name 要查询的目录的名称。这是作为应用程序数据的一部分创建的目录。 mode 操作模式。

source

pub fn move_database_from(&self, source_context: &Self, name: String) -> bool

将现有数据库文件从给定的源存储上下文移动到此上下文。这通常用于在升级后在存储位置之间迁移数据,例如迁移到受设备保护的存储。移动数据库之前必须关闭数据库。 返回:如果移动成功或源上下文中不存在数据库,则返回 true,否则返回 false。 source_context 包含要移动的现有数据库的源上下文。 name 数据库文件的名称。

source

pub fn get_database_path(&self, name: String) -> File

返回文件系统上存储使用 openOrCreateDatabase 创建的数据库的绝对路径。如果调用应用程序移动到采用的存储设备,则返回的路径可能会随时间而变化,因此只应保留相对路径。 返回:给定数据库的绝对路径。 name 您想要获取其路径的数据库的名称。

Methods from Deref<Target = GlobalRef>§

source

pub fn as_obj(&self) -> &JObject<'static>

Get the object from the global ref

This borrows the ref and prevents it from being dropped as long as the JObject sticks around.

Methods from Deref<Target = JObject<'static>>§

source

pub fn as_raw(&self) -> *mut _jobject

Returns the raw JNI pointer.

Trait Implementations§

source§

impl Debug for ContextWrapper

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for ContextWrapper

§

type Target = Context

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<&GlobalRef> for ContextWrapper

source§

fn from(obj: &GlobalRef) -> Self

Converts to this type from the input type.
source§

impl Into<GlobalRef> for &ContextWrapper

source§

fn into(self) -> GlobalRef

Converts this type into the (usually inferred) input type.
source§

impl JObjNew for ContextWrapper

§

type Fields = ()

字段类型
source§

fn _new(this: &GlobalRef, fields: Self::Fields) -> Self

从java对象创建本地对象。 this java对象引用。
source§

fn null() -> Self
where Self: Sized, Self::Fields: Default,

创建空对象。
source§

impl JObjRef for ContextWrapper

source§

fn java_ref(&self) -> GlobalRef

获取java对象引用。
source§

impl JType for ContextWrapper

§

type Error = Error

错误类型。
source§

const CLASS: &'static str = "android/content/ContextWrapper"

java类的名称。
source§

const OBJECT_SIG: &'static str = "Landroid/content/ContextWrapper;"

对象的签名描述。
source§

impl PartialEq for ContextWrapper

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToString for ContextWrapper

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.