2022年7月21日

Android Q以下版本(不包含Q) 獲取存檔權限

 



    private  void load_write_permession(){

        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M  && Build.VERSION.SDK_INT<Build.VERSION_CODES.Q){

            if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissionLauncher.launch(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE);
            }
        }

    }
    private ActivityResultLauncher<String> requestPermissionLauncher =
            registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {

                if (isGranted) {

                } else {

                    finish(); //CLOSE
                }
            });

沒有留言:

張貼留言