要真正回答你的问题,如果你有根,你可以用反射来做。我已经在android 4.1上完成了,在其他平台上它的工作方式可能不同。好处是共享首选项不能仅通过系统服务访问,因此您可以通过反射访问“隐藏”方法。把它放在试试看:
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /data/data/package_name/shared_prefs/package_name_preferences.xml" });
proc.waitFor();
proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /data/data/package_name/shared_prefs" });
proc.waitFor();
proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "chmod 777 /data/data/package_name" });
proc.waitFor();
File preffile = new File("/data/data/package_name/shared_prefs/package_name_preferences.xml");
Class prefimplclass = Class.forName("android.app.SharedPreferencesImpl");
Constructor prefimplconstructor = prefimplclass.getDeclaredConstructor(File.class,int.class);
prefimplconstructor.setAccessible(true);
Object prefimpl = prefimplconstructor.newInstance(preffile,Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
Editor editor = (Editor) prefimplclass.getMethod("edit").invoke(prefimpl);
//put your settings here
editor.commit();
你需要使用系统签名来签署你的应用程序才能获得该许可,这是不容易获得的。 –