android read_logs这权限有什么用,对Jelly Bean的READ_LOGS权限(API 16)
您可以通过从您的应用程序执行pm grant命令来获得对根设备的许可。不过,为了使更改生效,您可能必须在此之后重新启动应用程序:String pname = getPackageName();String[] CMDLINE_GRANTPERMS = { "su", "-c", null };if (getPackageManager().checkPermission(android.Manif
您可以通过从您的应用程序执行pm grant命令来获得对根设备的许可。不过,为了使更改生效,您可能必须在此之后重新启动应用程序:
String pname = getPackageName();
String[] CMDLINE_GRANTPERMS = { "su", "-c", null };
if (getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, pname) != 0) {
Log.d(TAG, "we do not have the READ_LOGS permission!");
if (android.os.Build.VERSION.SDK_INT >= 16) {
Log.d(TAG, "Working around JellyBeans 'feature'...");
try {
// format the commandline parameter
CMDLINE_GRANTPERMS[2] = String.format("pm grant %s android.permission.READ_LOGS", pname);
java.lang.Process p = Runtime.getRuntime().exec(CMDLINE_GRANTPERMS);
int res = p.waitFor();
Log.d(TAG, "exec returned: " + res);
if (res != 0)
throw new Exception("failed to become root");
} catch (Exception e) {
Log.d(TAG, "exec(): " + e);
Toast.makeText(context, "Failed to obtain READ_LOGS permission", Toast.LENGTH_LONG).show();
}
}
} else
Log.d(TAG, "we have the READ_LOGS permission already!");
该代码应从您的onCreate()中调用。授予权限后,就不再需要root用户权限。
PS:Superuser应用程序上的p.waitFor()会阻塞,从而延迟了应用程序的启动并可能导致ANR。
更多推荐
所有评论(0)