你好我想问一下,我设置Android systemproperty,在manifest中也设置了
android:sharedUserId="android.uid.system"
但是通过set设置属性的时候还是
Unable to set property "persist.sys.com.example.android.camera2basic" to "passed": connection failed; errno=13 (Permission denied)
我通过反射的方法设置的
package com.example.android.camera2basic;
import android.util.Log;
import java.lang.reflect.Method;
public class PropertyUtils {
private static volatile Method set = null;
private static volatile Method get = null;
public static void set(String prop, String value) {
try {
if (null == set) {
synchronized (PropertyUtils.class) {
if (null == set) {
Class<?> cls = Class.forName("android.os.SystemProperties");
set = cls.getDeclaredMethod("set", new Class<?>[]{String.class, String.class});
}
}
}
Log.e("debug", "set: *** come here ?");
set.invoke(null, new Object[]{prop, value});
Log.e("debug", "set: *** come here2 ?");
} catch (Throwable e) {
Log.e("debug", "set: *** come here catch?");
e.printStackTrace();
}
}
public static String get(String prop, String defaultvalue) {
String value = defaultvalue;
try {
if (null == get) {
synchronized (PropertyUtils.class) {
if (null == get) {
Class<?> cls = Class.forName("android.os.SystemProperties");
get = cls.getDeclaredMethod("get", new Class<?>[]{String.class, String.class});
}
}
}
value = (String) (get.invoke(null, new Object[]{prop, defaultvalue}));
} catch (Throwable e) {
e.printStackTrace();
}
return value;
}
}
(Permission denied) 这就提示你了嘛,权限不够。你的是root设备吗?还是你有系统签名呢?
代码应该没啥错
这个权限有吗?
另外,你可以通过adb 去读取和写一下属性值。
读取属性值
getprop xxx
设置属性值
setprop xxx value