如何解决执行“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 举报,一经查实,本站将立刻删除。