虽然它仍然抛出相同的权限异常。经过一番搜索,我得到了答案,为了获得 INJECT_EVENTS 权限,您的应用程序必须使用与系统签名相同的签名。但是我不清楚这到底意味着什么。有没有一种方法可以在我无法访问相同签名的情况下保持中间状态。
在/system/app中安装您的应用
[正如您所说,您将为您的应用授予用户 root 访问权限]
而且,以 root 身份运行的应用不需要任何正常的 Android android 权限,因为它已经获得了可用的最高级别权限
1。首先,获取apk在系统中所在的位置,放到sdcard中。
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> apps = getPackageManager().queryIntentActivities(mainIntent, 0);
for (ResolveInfo info : apps) {
File fx = new File(info.activityInfo.applicationInfo.publicSourceDir);
if(fx.getName().toString().contains(getApplicationContext().getPackageName())){
File fz = new File(Environment.getExternalStorageDirectory().toString());
fz.mkdirs();
fz = new File(fz.getPath()+"/"+getApplicationContext().getPackageName()+".apk");
fz.createNewFile();
InputStream in = new FileInputStream(fx);
OutputStream out = new FileOutputStream(fz);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
2。执行以下命令将/system目录重新挂载为读/写,并将应用程序从SDCARD安装到/system/app目录,其中system:
Runtime.getRuntime.exec("su -c mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system");
String x = getApplicationContext().getPackageName();
Runtime.getRuntime.exec("su -c cp /sdcard/"+x+".apk /system/app");
Runtime.getRuntime.exec("su -c reboot");
现在,尝试执行您的代码并发表评论。