Android acquires permissions dynamically, and EasyPermissions.hasPermissions returns true. Why?

wrote a pure demo to try EasyPermissions, and the code was posted. In this sentence of EasyPermissions.hasPermissions (this, perms) applying for permission, the return will always be true. It is puzzling, and there is a lot of advice from various gods

.
public class TestActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks{

    public final static String TAG = TestActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        TextView t = findViewById(R.id.textView_top_title);
        t.setText("");
        findViewById(R.id.button_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                requestPermissions();
            }
        });


    }
    private static final int RC_CAMERA_AND_RECORD_AUDIO = 10000;
    /**
     * 
     */
    private void requestPermissions() {
        String[] perms = {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION};

        //
        if (EasyPermissions.hasPermissions(this, perms)) {
            // , 
            openCamera();
        } else {
            // , 
            // this: 
            // Dialog
            // RC_CAMERA_AND_RECORD_AUDIO , 
            // perms 
            EasyPermissions.requestPermissions(this, ", ", RC_CAMERA_AND_RECORD_AUDIO, perms);
        }
    }

    private void openCamera(){
        Toast.makeText(this, "", Toast.LENGTH_SHORT)
                .show();
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE) {
            // Do something after user returned from app settings screen, like showing a Toast.
            Toast.makeText(this, "", Toast.LENGTH_SHORT)
                    .show();
        }
    }





    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        // Forward results to EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> list) {
        // Some permissions have been granted
        Log.d(TAG, "onPermissionsGranted:" + requestCode + ":" + list.size());
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> list) {
        Log.d(TAG, "onPermissionsDenied:" + requestCode + ":" + list.size());

        // (Optional) Check whether the user denied any permissions and checked "NEVER ASK AGAIN."
        // This will display a dialog directing them to enable the permission in app settings.
        if (EasyPermissions.somePermissionPermanentlyDenied(this, list)) {
            new AppSettingsDialog.Builder(this).build().show();
        }
    }
}

Jun.29,2022

Runtime permissions are introduced by Android M (6.0)
  • if the system version is less than 6.0, then EasyPermissions.hasPermissions (Context, String []) of course returns true (if you declare permission requirements in AndroidManifest.xml).
  • in addition, if the user is authorized, it will naturally return true .
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c58e89-348a7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c58e89-348a7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?