Thursday, 27 December 2018

Making app package as device owner using command programtically

I have been working on making the package as device owner but did not found any success. I have rooted my device for the same. I am using this command.

                val exe = ShellExecuter()
                var command = "dpm set-device-owner $packageName/ .MyDeviceAdminReceiver"
                val outp = exe.Executer(command)

ShellExecuter snippet

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 snippet

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 snippet

<?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>

I want to make my rooted device owner of my app package programmatically using commands or any other way if anybody can suggest. Thanks in Advance.



from Making app package as device owner using command programtically

No comments:

Post a Comment