SettingsProvider之Settings.System(Secure)-------Action

本文列举了Android系统中用于启动不同设置界面的Intent Action,包括系统设置、网络配置、安全选项等,为开发者提供快速调用系统设置界面的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载请注明出处:http://blog.youkuaiyun.com/droyon/article/details/35558751

SettingsProvider包含了许多我们经常使用到的action,先列出如下;

1、进入系统设置的action
/**
     * Activity Action: Show system settings.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_SETTINGS = "android.settings.SETTINGS";
2、进入APN设置
/**
     * Activity Action: Show settings to allow configuration of APNs.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_APN_SETTINGS = "android.settings.APN_SETTINGS";
3、无线和网络相关设置。
/**
     * Activity Action: Show settings to allow configuration of wireless controls
     * such as Wi-Fi, Bluetooth and Mobile networks.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_WIRELESS_SETTINGS =
            "android.settings.WIRELESS_SETTINGS";
4、显示让你操作飞行模式的action。
/**
     * Activity Action: Show settings to allow entering/exiting airplane mode.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_AIRPLANE_MODE_SETTINGS =
            "android.settings.AIRPLANE_MODE_SETTINGS";
5、辅助功能action。
/**
     * Activity Action: Show settings for accessibility modules.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_ACCESSIBILITY_SETTINGS =
            "android.settings.ACCESSIBILITY_SETTINGS";
6、安全设置的action
/**
     * Activity Action: Show settings to allow configuration of security and
     * location privacy.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_SECURITY_SETTINGS =
            "android.settings.SECURITY_SETTINGS";
7、受信任的证书
/**
     * Activity Action: Show trusted credentials settings, opening to the user tab,
     * to allow management of installed credentials.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_TRUSTED_CREDENTIALS_USER =
            "com.android.settings.TRUSTED_CREDENTIALS_USER";
8、备份重置action
/**
     * Activity Action: Show settings to allow configuration of privacy options.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_PRIVACY_SETTINGS =
            "android.settings.PRIVACY_SETTINGS";
9、wifi设置的action
 /**
     * Activity Action: Show settings to allow configuration of Wi-Fi.

     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.

     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_WIFI_SETTINGS =
            "android.settings.WIFI_SETTINGS";
10、wifi高级设置的wifi
/**
     * Activity Action: Show settings to allow configuration of a static IP
     * address for Wi-Fi.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you safeguard
     * against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_WIFI_IP_SETTINGS =
            "android.settings.WIFI_IP_SETTINGS";
11、蓝牙设置
/**
     * Activity Action: Show settings to allow configuration of Bluetooth.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_BLUETOOTH_SETTINGS =
            "android.settings.BLUETOOTH_SETTINGS";
12、wifi投影设置
/**
     * Activity Action: Show settings to allow configuration of Wifi Displays.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_WIFI_DISPLAY_SETTINGS =
            "android.settings.WIFI_DISPLAY_SETTINGS";
13、时间和日期设置
/**
     * Activity Action: Show settings to allow configuration of date and time.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_DATE_SETTINGS =
            "android.settings.DATE_SETTINGS";
14、声音设置
/**
     * Activity Action: Show settings to allow configuration of sound and volume.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_SOUND_SETTINGS =
            "android.settings.SOUND_SETTINGS";
15、显示设置
/**
     * Activity Action: Show settings to allow configuration of display.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_DISPLAY_SETTINGS =
            "android.settings.DISPLAY_SETTINGS";
16、时区设置
/**
     * Activity Action: Show settings to allow configuration of locale.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_LOCALE_SETTINGS =
            "android.settings.LOCALE_SETTINGS";
17、输入法设置
/**
     * Activity Action: Show settings to configure input methods, in particular
     * allowing the user to enable input methods.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_INPUT_METHOD_SETTINGS =
            "android.settings.INPUT_METHOD_SETTINGS";
18、应用设置
/**
     * Activity Action: Show settings to allow configuration of application-related settings.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_APPLICATION_SETTINGS =
            "android.settings.APPLICATION_SETTINGS";
19、系统更新设置
/**
     * Activity Action: Show settings for system update functionality.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_SYSTEM_UPDATE_SETTINGS =
            "android.settings.SYSTEM_UPDATE_SETTINGS";
20、添加账户设置
/**
     * Activity Action: Show add account screen for creating a new account.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * The account types available to add may be restricted by adding an {@link #EXTRA_AUTHORITIES}
     * extra to the Intent with one or more syncable content provider's authorities.  Only account
     * types which can sync with that content provider will be offered to the user.
     * <p>
     * Account types can also be filtered by adding an {@link #EXTRA_ACCOUNT_TYPES} extra to the
     * Intent with one or more account types.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_ADD_ACCOUNT =
            "android.settings.ADD_ACCOUNT_SETTINGS";
21、关于手机设置
/**
     * Activity Action: Show general device information settings (serial
     * number, software version, phone number, etc.).
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_DEVICE_INFO_SETTINGS =
        "android.settings.DEVICE_INFO_SETTINGS";
22、NFC设置
/**
     * Activity Action: Show NFC settings.
     * <p>
     * This shows UI that allows NFC to be turned on or off.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing
     * @see android.nfc.NfcAdapter#isEnabled()
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_NFC_SETTINGS = "android.settings.NFC_SETTINGS";
23、互动屏保设置
/**
     * Activity Action: Show Daydream settings.
     * <p>
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * <p>
     * Input: Nothing.
     * <p>
     * Output: Nothing.
     * @see android.service.dreams.DreamService
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_DREAM_SETTINGS = "android.settings.DREAM_SETTINGS";
24、


<think>嗯,用户遇到了一个Java中的IllegalArgumentException,具体是android.provider.Settings组件不存在的问题。首先,我需要理解这个错误的原因。通常,当代码中引用了不存在的类或方法时,会抛出这样的异常。可能的情况包括: 1. **错误的类或方法引用**:用户可能错误地拼写了Settings类中的某个方法或常量。比如,Settings.System.getString()是否存在?或者是不是使用了已经被废弃的API? 2. **API级别问题**:某些Settings的方法只在特定的Android版本中可用。如果用户的项目设置的minSdkVersion低于方法引入的版本,可能会导致在旧设备上运行时找不到该方法,从而引发错误。 3. **权限问题**:访问系统设置可能需要特定的权限,比如WRITE_SETTINGS。如果没有在AndroidManifest.xml中声明这些权限,可能会导致访问失败,但通常权限问题会引发SecurityException而不是IllegalArgumentException,所以这个可能性较低,但也不能完全排除。 接下来,我需要回忆Android开发中Settings组件的使用方式。android.provider.Settings类确实存在,但其中的方法和常量可能分布在不同的子类中,比如System、Global、Secure等。例如,读取系统设置通常使用Settings.System,而全局设置使用Settings.Global。如果用户错误地调用了不存在的子类或方法,比如直接使用Settings.getString()而不指定正确的子类,就会导致错误。 另外,检查用户提到的引用来源[^1],即packages/apps/Settings/src/com/android/settings/LocalePicker.java,这可能是一个AOSP中的内部类。普通应用开发中,无法直接访问com.android.settings包下的类,因为它们属于系统级代码,未公开给第三方应用。如果用户尝试调用这些内部类,自然会导致类找不到的异常。 解决方案可能包括: - 确认使用的Settings类和方法是否正确,比如检查是否有拼写错误,是否导入了正确的类。 - 检查API级别,确保调用的方法在项目支持的minSdkVersion以上可用。 - 避免使用内部或隐藏的API,改用公开的API。 - 确保声明了必要的权限。 还需要考虑用户是否混淆了不同的Settings子类。例如,Settings.System用于设备系统设置,而Settings.Secure用于安全相关的设置,这些可能需要不同的权限,并且某些设置可能无法被第三方应用修改。 另外,在Android高版本中,某些系统设置的访问可能受到限制,比如从Android 6.0开始,WRITE_SETTINGS权限需要动态申请,而不仅仅是静态声明。但即便如此,这通常会导致权限被拒绝,而不是类不存在的异常。 用户提到的错误信息明确指出“android.provider.Settings does not exist”,这可能意味着代码中没有正确导入该类,或者构建配置有问题,导致无法找到该类的引用。不过,这种情况比较少见,因为android.provider.Settings是框架的一部分,只要项目正确配置了Android SDK,应该可以正常导入。 综合来看,最可能的错误是用户误用了内部API,例如引用了com.android.settings中的类,而不是公开的android.provider.Settings类。或者,在调用Settings的方法时,没有正确指定子类,如System、Global或Secure,导致找不到对应的方法或常量。 所以,解决方案应指导用户检查代码中的类引用是否正确,确保使用公开的API,并验证API级别和权限设置。同时,提醒用户避免使用系统内部类,因为这些类在第三方应用中不可访问。</think>### 解决方案:解决 `java.lang.IllegalArgumentException: android.provider.Settings does not exist` #### 1. 检查类引用和拼写 - **问题**:代码中可能错误引用了 `android.provider.Settings` 的子类或方法。 **解决**:确认是否使用了正确的类路径和方法。例如: ```java // 正确示例:访问系统设置 String value = Settings.System.getString(getContentResolver(), Settings.System.AIRPLANE_MODE_ON); ``` 确保类名和常量名拼写正确(如 `System`、`Secure`、`Global` 是 `Settings` 的子类)。 #### 2. 验证API兼容性 - **问题**:部分 `Settings` 方法需要特定API级别支持(如 `Settings.Global` 仅支持API 17+)。 **解决**:在 `build.gradle` 中检查 `minSdkVersion` 是否低于方法要求: ```groovy android { defaultConfig { minSdkVersion 21 // 根据实际需求调整 } } ``` 若需兼容低版本,需添加版本判断: ```java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { String value = Settings.Global.getString(...); } ``` #### 3. 避免调用内部类 - **问题**:引用系统内部类(如 `com.android.settings.LocalePicker`)会导致类不存在异常。 **解决**:仅使用公开的API(如 `android.provider.Settings` 下的类)。 ```java // 错误示例:尝试调用系统内部类 import com.android.settings.LocalePicker; // 不可访问! // 正确示例:使用公开的API实现语言切换 Resources res = getResources(); Configuration config = res.getConfiguration(); config.setLocale(new Locale("zh", "CN")); res.updateConfiguration(config, res.getDisplayMetrics()); ``` #### 4. 检查权限声明 - **问题**:未声明 `WRITE_SETTINGS` 等权限可能导致操作失败。 **解决**:在 `AndroidManifest.xml` 中添加权限: ```xml <uses-permission android:name="android.permission.WRITE_SETTINGS" /> ``` 注意:从 Android 6.0(API 23)开始,`WRITE_SETTINGS` 需动态申请权限: ```java if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.System.canWrite(context)) { Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + context.getPackageName())); startActivity(intent); } } ``` --- ### 相关问题 1. **如何动态申请 `WRITE_SETTINGS` 权限?** - 需要检查系统版本,使用 `Settings.ACTION_MANAGE_WRITE_SETTINGS` 跳转授权界面。 2. **`Settings.System` 和 `Settings.Global` 有何区别?** - `System` 存储设备级别的设置(如屏幕亮度),`Global` 存储全局用户无关的设置(如ADB启用状态)。 3. **如何兼容不同Android版本的设置操作?** - 使用 `Build.VERSION.SDK_INT` 判断版本,并调用对应API或提供降级逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hailushijie

您的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值