执行“put”时发生异常

问题描述

我正在尝试通过应用程序以编程方式运行 adb shell 命令以更改 rtt_calling_mode 变量值,但我遇到了此错误

 Exception occurred while executing 'put':
 java.lang.NullPointerException
    at java.util.Objects.requireNonNull(Objects.java:220)
    at com.android.server.appop.AppOpsService.checkPackage(AppOpsService.java:2969)
    at android.app.AppOpsManager.checkPackage(AppOpsManager.java:7697)
    at android.content.ContentProvider.getCallingPackage(ContentProvider.java:954)
    at com.android.providers.settings.SettingsProvider.mutateSecureSetting(SettingsProvider.java:1732)
    at com.android.providers.settings.SettingsProvider.insertSecureSetting(SettingsProvider.java:1652)
    at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:412)
    at android.content.ContentProvider.call(ContentProvider.java:2448)
    at android.content.ContentProvider$Transport.call(ContentProvider.java:517)
    at com.android.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:375)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:277)
    at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
    at android.os.ShellCommand.exec(ShellCommand.java:44)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:49)
    at android.os.Binder.shellCommand(Binder.java:929)
    at android.os.Binder.onTransact(Binder.java:813)
    at android.os.Binder.execTransactInternal(Binder.java:1159)
    at android.os.Binder.execTransact(Binder.java:1123)

在 A10 上运行时,我能够完美地运行此命令,它会更改 RTT 变量,就像我通过命令提示符运行命令“adb shell settings put secure rtt_calling_mode0 1”一样。但是现在在 A11 版本上我收到此错误。我不确定是什么导致了这个问题,以及为什么它现在出现了“put”问题。也不确定 NullPointerException 来自哪里。有谁知道是什么导致了这个问题?下面是运行时抛出错误代码

public static String setRealTimeText(int simslot,int enabled){
        String command = "settings put secure rtt_calling_mode" + slot +  " " + enabled;

        try {
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
            BufferedReader errorOutput = new BufferedReader(new InputStreamReader(process.getErrorStream()));

            //get the error output
            String s = "";
            String outputString = "";

            if (errorOutput.readLine() != null) {
                while ((s = errorOutput.readLine()) != null) {
                    outputString += " " + s + "\n";
                }
                return outputString;
            }

            //get the console output
            while ((s = output.readLine()) != null) {
                outputString += "- " + s + "\n";
            }
            return "RTT was enabled"

        } catch (Exception e) {
            e.printstacktrace();
            return e.toString();
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)