It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
已关闭8年。
我正在尝试解析android的
但是我遇到一个错误,这是StackTraCE:
已关闭8年。
我正在尝试解析android的
getprop
命令。这是我正在使用的代码。public class PropManager {
public String propReader() {
InputStream inputstream = null;
try {
inputstream = Runtime.getRuntime().exec("/system/bin/getprop")
.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
String propval = "";
try {
propval = new Scanner(inputstream).useDelimiter("\\A").next();
System.out.println(propval);
} catch (NoSuchElementException e) {
e.printStackTrace();
}
return propval;
}
public String DeviceProp(String propval) {
String deviceprop = "none";
try {
Scanner scanner = new Scanner(propval).useDelimiter("\\n");
scanner.findWithinHorizon(
Pattern.compile("\\[ro.product.model\\].*\\[([^\\0]+)\\]"),
0);
mbvsprop = scanner.match().group(1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return deviceprop;
}
}
但是我遇到一个错误,这是StackTraCE:
03-30 08:07:49.317: I/System.out(5055): [ARGH]: [ARGH]
03-30 08:07:49.317: I/System.out(5055): [dalvik.vm.heapsize]: [48m]
03-30 08:07:49.317: I/System.out(5055): [dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
03-30 08:07:49.317: I/System.out(5055): [dev.bootcomplete]: [1]
03-30 08:07:49.317: I/System.out(5055): [gsm.current.phone-type]: [1]
03-30 08:07:49.317: I/System.out(5055): [gsm.defaultpdpcontext.active]: [true]
03-30 08:07:49.317: I/System.out(5055): [gsm.network.type]: [UMTS:3]
03-30 08:07:49.317: I/System.out(5055): [gsm.nitz.time]: [1333077079197]
03-30 08:07:49.317: I/System.out(5055): [gsm.operator.alpha]: [Android]
03-30 08:07:49.317: I/System.out(5055): [gsm.operator.iso-country]: [us]
03-30 08:07:49.317: I/System.out(5055): [gsm.operator.isroaming]: [false]
03-30 08:07:49.317: I/System.out(5055): [gsm.operator.numeric]: [310260]
03-30 08:07:49.317: I/System.out(5055): [gsm.sim.operator.alpha]: [Android]
03-30 08:07:49.327: I/System.out(5055): [gsm.sim.operator.iso-country]: [us]
03-30 08:07:49.327: I/System.out(5055): [gsm.sim.operator.numeric]: [310260]
03-30 08:07:49.327: I/System.out(5055): [gsm.sim.state]: [READY]
03-30 08:07:49.327: I/System.out(5055): [gsm.version.ril-impl]: [android reference-ril 1.0]
03-30 08:07:49.327: I/System.out(5055): [init.svc.adbd]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.bootanim]: [stopped]
03-30 08:07:49.327: I/System.out(5055): [init.svc.console]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.debuggerd]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.goldfish-logcat]: [stopped]
03-30 08:07:49.327: I/System.out(5055): [init.svc.goldfish-setup]: [stopped]
03-30 08:07:49.327: I/System.out(5055): [init.svc.installd]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.keystore]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.media]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.netd]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.qemu-props]: [stopped]
03-30 08:07:49.327: I/System.out(5055): [init.svc.qemud]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.ril-daemon]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.servicemanager]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.surfaceflinger]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.vold]: [running]
03-30 08:07:49.327: I/System.out(5055): [init.svc.zygote]: [running]
03-30 08:07:49.337: I/System.out(5055): [net.bt.name]: [Android]
03-30 08:07:49.337: I/System.out(5055): [net.change]: [net.dnschange]
03-30 08:07:49.337: I/System.out(5055): [net.dns1]: [10.0.2.3]
03-30 08:07:49.337: I/System.out(5055): [net.dnschange]: [1]
03-30 08:07:49.337: I/System.out(5055): [net.eth0.dns1]: [10.0.2.3]
03-30 08:07:49.337: I/System.out(5055): [net.eth0.gw]: [10.0.2.2]
03-30 08:07:49.337: I/System.out(5055): [net.gprs.local-ip]: [10.0.2.15]
03-30 08:07:49.337: I/System.out(5055): [net.hostname]: [android-ab5e8b1dff91e7d5]
03-30 08:07:49.337: I/System.out(5055): [net.qtaguid_enabled]: [0]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.default]: [4096,87380,110208,4096,16384,110208]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.edge]: [4093,26280,35040,4096,16384,35040]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.gprs]: [4092,8760,11680,4096,8760,11680]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.hspa]: [4094,87380,262144,4096,16384,262144]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.lte]: [524288,1048576,2097152,262144,524288,1048576]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.umts]: [4094,87380,110208,4096,16384,110208]
03-30 08:07:49.337: I/System.out(5055): [net.tcp.buffersize.wifi]: [524288,1048576,2097152,262144,524288,1048576]
03-30 08:07:49.337: I/System.out(5055): [persist.sys.country]: [US]
03-30 08:07:49.337: I/System.out(5055): [persist.sys.language]: [en]
03-30 08:07:49.337: I/System.out(5055): [persist.sys.localevar]: []
03-30 08:07:49.337: I/System.out(5055): [persist.sys.profiler_ms]: [0]
03-30 08:07:49.337: I/System.out(5055): [persist.sys.timezone]: [GMT]
03-30 08:07:49.337: I/System.out(5055): [persist.sys.usb.config]: [adb]
03-30 08:07:49.337: I/System.out(5055): [qemu.hw.mainkeys]: [1]
03-30 08:07:49.337: I/System.out(5055): [qemu.sf.fake_camera]: [back]
03-30 08:07:49.337: I/System.out(5055): [qemu.sf.lcd_density]: [120]
03-30 08:07:49.337: I/System.out(5055): [rild.libargs]: [-d /dev/ttyS0]
03-30 08:07:49.337: I/System.out(5055): [rild.libpath]: [/system/lib/libreference-ril.so]
03-30 08:07:49.337: I/System.out(5055): [ro.allow.mock.location]: [1]
03-30 08:07:49.337: I/System.out(5055): [ro.baseband]: [unknown]
03-30 08:07:49.337: I/System.out(5055): [ro.board.platform]: []
03-30 08:07:49.337: I/System.out(5055): [ro.bootloader]: [unknown]
03-30 08:07:49.337: I/System.out(5055): [ro.bootmode]: [unknown]
03-30 08:07:49.357: I/System.out(5055): [ro.build.characteristics]: [default]
03-30 08:07:49.357: I/System.out(5055): [ro.build.date.utc]: [1323837732]
03-30 08:07:49.357: I/System.out(5055): [ro.build.date]: [Tue Dec 13 20:42:11 PST 2011]
03-30 08:07:49.357: I/System.out(5055): [ro.build.description]: [sdk-eng 4.0.3 MR1 237985 test-keys]
03-30 08:07:49.357: I/System.out(5055): [ro.build.display.id]: [sdk-eng 4.0.3 MR1 237985 test-keys]
03-30 08:07:49.357: I/System.out(5055): [ro.build.fingerprint]: [generic/sdk/generic:4.0.3/MR1/237985:eng/test-keys]
03-30 08:07:49.357: I/System.out(5055): [ro.build.host]: [android-test-34.mtv.corp.google.com]
03-30 08:07:49.357: I/System.out(5055): [ro.build.id]: [MR1]
03-30 08:07:49.357: I/System.out(5055): [ro.build.product]: [generic]
03-30 08:07:49.357: I/System.out(5055): [ro.build.tags]: [test-keys]
03-30 08:07:49.357: I/System.out(5055): [ro.build.type]: [eng]
03-30 08:07:49.357: I/System.out(5055): [ro.build.user]: [android-build]
03-30 08:07:49.357: I/System.out(5055): [ro.build.version.codename]: [REL]
03-30 08:07:49.357: I/System.out(5055): [ro.build.version.incremental]: [237985]
03-30 08:07:49.357: I/System.out(5055): [ro.build.version.release]: [4.0.3]
03-30 08:07:49.357: I/System.out(5055): [ro.build.version.sdk]: [15]
03-30 08:07:49.357: I/System.out(5055): [ro.carrier]: [unknown]
03-30 08:07:49.357: I/System.out(5055): [ro.com.google.locationfeatures]: [1]
03-30 08:07:49.357: I/System.out(5055): [ro.config.alarm_alert]: [Alarm_Classic.ogg]
03-30 08:07:49.357: I/System.out(5055): [ro.config.nocheckin]: [yes]
03-30 08:07:49.357: I/System.out(5055): [ro.config.notification_sound]: [OnTheHunt.ogg]
03-30 08:07:49.357: I/System.out(5055): [ro.crypto.state]: [unencrypted]
03-30 08:07:49.357: I/System.out(5055): [ro.debuggable]: [1]
03-30 08:07:49.357: I/System.out(5055): [ro.factorytest]: [0]
03-30 08:07:49.357: I/System.out(5055): [ro.hardware]: [goldfish]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.android.checkjni]: [1]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.android.qemud]: [ttyS1]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.console]: [ttyS0]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.ndns]: [1]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.qemu.gles]: [0]
03-30 08:07:49.357: I/System.out(5055): [ro.kernel.qemu]: [1]
03-30 08:07:49.357: I/System.out(5055): [ro.product.board]: []
03-30 08:07:49.357: I/System.out(5055): [ro.product.brand]: [generic]
03-30 08:07:49.357: I/System.out(5055): [ro.product.cpu.abi2]: [armeabi]
03-30 08:07:49.357: I/System.out(5055): [ro.product.cpu.abi]: [armeabi-v7a]
03-30 08:07:49.357: I/System.out(5055): [ro.product.device]: [generic]
03-30 08:07:49.367: I/System.out(5055): [ro.product.locale.language]: [en]
03-30 08:07:49.367: I/System.out(5055): [ro.product.locale.region]: [US]
03-30 08:07:49.367: I/System.out(5055): [ro.product.manufacturer]: [unknown]
03-30 08:07:49.367: I/System.out(5055): [ro.product.model]: [sdk]
03-30 08:07:49.367: I/System.out(5055): [ro.product.name]: [sdk]
03-30 08:07:49.367: I/System.out(5055): [ro.radio.use-ppp]: [no]
03-30 08:07:49.367: I/System.out(5055): [ro.revision]: [0]
03-30 08:07:49.367: I/System.out(5055): [ro.runtime.firstboot]: [1333077089134]
03-30 08:07:49.367: I/System.out(5055): [ro.secure]: [0]
03-30 08:07:49.367: I/System.out(5055): [ro.serialno]: []
03-30 08:07:49.367: I/System.out(5055): [ro.setupwizard.mode]: [OPTIONAL]
03-30 08:07:49.367: I/System.out(5055): [ro.wifi.channels]: []
03-30 08:07:49.367: I/System.out(5055): [status.battery.level]: [5]
03-30 08:07:49.367: I/System.out(5055): [status.battery.level_raw]: [50]
03-30 08:07:49.367: I/System.out(5055): [status.battery.level_scale]: [9]
03-30 08:07:49.367: I/System.out(5055): [status.battery.state]: [Slow]
03-30 08:07:49.367: I/System.out(5055): [sys.boot_completed]: [1]
03-30 08:07:49.367: I/System.out(5055): [sys.settings_system_version]: [1]
03-30 08:07:49.367: I/System.out(5055): [sys.usb.config]: [adb]
03-30 08:07:49.377: I/System.out(5055): [sys.usb.state]: [adb]
03-30 08:07:49.377: I/System.out(5055): [system_init.startsurfaceflinger]: [0]
03-30 08:07:49.377: I/System.out(5055): [xmpp.auto-presence]: [true]
03-30 08:07:49.377: W/System.err(5055): java.util.regex.PatternSyntaxException: Unrecognized backslash escape sequence in pattern near index 30:
03-30 08:07:49.377: W/System.err(5055): \[ro.product.model\].*\[([^\0]+)\]
03-30 08:07:49.377: W/System.err(5055): ^
03-30 08:07:49.377: W/System.err(5055): at java.util.regex.Pattern.compileImpl(Native Method)
03-30 08:07:49.377: W/System.err(5055): at java.util.regex.Pattern.compile(Pattern.java:400)
03-30 08:07:49.377: W/System.err(5055): at java.util.regex.Pattern.<init>(Pattern.java:383)
03-30 08:07:49.377: W/System.err(5055): at java.util.regex.Pattern.compile(Pattern.java:374)
03-30 08:07:49.377: W/System.err(5055): at prop.test.PropManager.DeviceProp(PropManager.java:97)
03-30 08:07:49.387: W/System.err(5055): at prop.test.PropManager.propArray(PropManager.java:113)
03-30 08:07:49.387: W/System.err(5055): at prop.test.ProptestActivity.onCreate(ProptestActivity.java:20)
03-30 08:07:49.387: W/System.err(5055): at android.app.Activity.performCreate(Activity.java:4465)
03-30 08:07:49.387: W/System.err(5055): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-30 08:07:49.387: W/System.err(5055): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-30 08:07:49.387: W/System.err(5055): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-30 08:07:49.387: W/System.err(5055): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-30 08:07:49.387: W/System.err(5055): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-30 08:07:49.387: W/System.err(5055): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 08:07:49.397: W/System.err(5055): at android.os.Looper.loop(Looper.java:137)
03-30 08:07:49.397: W/System.err(5055): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-30 08:07:49.397: W/System.err(5055): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 08:07:49.397: W/System.err(5055): at java.lang.reflect.Method.invoke(Method.java:511)
03-30 08:07:49.397: W/System.err(5055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-30 08:07:49.397: W/System.err(5055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-30 08:07:49.397: W/System.err(5055): at dalvik.system.NativeStart.main(Native Method)
最佳答案
仅仅通过阅读代码和大量输出就很难知道您要完成的工作,但是我将一探究竟。
特别是,不可能知道正则表达式中[^\\0]
的含义,但是如果您将其替换为一个点并使用问号将其设为非贪婪,则可以在下一行替换代码中的,应该做您想要的...
Pattern.compile("\\[ro.product.model\\].*\\[(.+?)\\]"),
关于java - 解析Android getprop ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9944747/
10-09 12:59