【问题标题】:How to detect whether user has turned on developer options in android如何检测用户是否在android中打开了开发者选项
【发布时间】:2020-04-27 10:11:39
【问题描述】:

我正在构建 React Native 应用程序,我想检测用户是否打开了开发人员选项。 在 MainActivity.java 文件中,我总是遇到 SettingNotFoundException 异常。

import android.provider.Settings.Secure;
import android.provider.Settings.Global;
import android.provider.Settings.SettingNotFoundException;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     try {
       int devOptions = Secure.getInt(this.getContentResolver(), Global.DEVELOPMENT_SETTINGS_ENABLED);
     }catch (SettingNotFoundException e){
        Log.d(getClass().getName(),  "Called"); 
     }
 }

【问题讨论】:

标签: android react-native-android


【解决方案1】:

使用此代码

       try {
            int devOptions = Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED);
            Log.d("DevOptions","Got Devoptions : "+devOptions);

        } catch (Settings.SettingNotFoundException e){
            Log.d(getClass().getName(),  "Called");
        }

并使用此导入语句

import android.provider.Settings;

【讨论】:

  • 我试过了,这并没有给出异常,但总是返回 0(无论开发人员选项设置如何)。这是否取决于android版本,因为找到这种方式的解决方案是在2013年给出的
  • 关于它对操作系统版本的依赖。我不这么认为。您正在尝试哪个版本?
  • Android Pie 及更高版本
  • 你知道其他方法吗?或为什么这不起作用?
猜你喜欢
  • 2022-01-09
  • 2010-10-25
  • 2022-12-13
  • 2015-10-13
  • 1970-01-01
  • 2015-06-11
  • 1970-01-01
  • 2018-02-19
  • 2023-03-30
相关资源
最近更新 更多