简体   繁体   中英

How to enable Android permissions with adb for all devices

I want all Android permissions to be activated automatically when installing the app.

I know I can enable all permissions on my device by installing the apk via adb.

adb install -g test.apk

Can I use this method for all devices or is there a way to enable permissions automatically?

I guess you will have to root your android device in order to provide all the available permissions for your app. Every time, activating the ADB shell for apk installation of the app is not viable. In order to avoid that, you can simply write this piece of code:

private void AllowPerm()
    {
        Log.d(TAG,"Allow all permissions: Prompting User...");
        
        // Defining the requierd permissions in the below String array.
        
        String[] perm={Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,};
        
        if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
                perm[0])== PackageManager.PERMISSION_GRANTED
                && ContextCompat.checkSelfPermission(this.getApplicationContext(),
                perm[1])==PackageManager.PERMISSION_GRANTED
                && ContextCompat.checkSelfPermission(this.getApplicationContext(),
                perm[2])==PackageManager.PERMISSION_GRANTED)
        {
            return;
        }

        else
        {
            ActivityCompat.requestperm(MainActivity.this,perm,REQUEST_CODE);
        }

    }

    @Override
    public void onRequestpermResult(int requestCode, @NonNull String[] perm, @NonNull int[] grantResults) {
        AllowPerm();
    }

You can give your desired permissions in the String array by looking at this Documentation

You can also perform the above step by manually declaring the PERMISSIONS in the AndroidManifest.xml (Refer this )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM