我一直在努力以设备所有者的身份制作软件包,但没有发现任何成功。我已经为我的设备植根了。我正在使用这个命令。
val exe = ShellExecuter()
var command = "dpm set-device-owner $packageName/ .MyDeviceAdminReceiver"
val outp = exe.Executer(command)
ShellExecuter 片段
public String Executer(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {`enter code here`
e.printStackTrace();
}
String response = output.toString();
return response;
}
MyDeviceAdminReceiver 片段
class MyDeviceAdminReceiver : DeviceAdminReceiver() {
companion object {
fun getComponentName(context: Context): ComponentName {
return ComponentName(context.applicationContext, MyDeviceAdminReceiver::class.java)
}
private val TAG = MyDeviceAdminReceiver::class.java.simpleName
}
override fun onLockTaskModeEntering(context: Context?, intent: Intent?, pkg: String?) {
super.onLockTaskModeEntering(context, intent, pkg)
Log.d(TAG, "onLockTaskModeEntering")
}
override fun onLockTaskModeExiting(context: Context?, intent: Intent?) {
super.onLockTaskModeExiting(context, intent)
Log.d(TAG, "onLockTaskModeExiting")
}
}
device_admin_reciever 片段
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<device-admin>
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>
如果有人可以建议,我想以编程方式使用命令或任何其他方式使我的应用程序包的根设备所有者。