-
권한요청 READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE
private static final int RequestExternalStorage = 1; private static String[] Permissions1 = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }; public static void verifyPermissions(Activity activity) { int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permission != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( activity, Permissions1, RequestExternalStorage ); } } // onRequestPermissionsResult함수 사용은 필수 아님, 결과 아록 싶을 때 boolean mPermissionAccepted = false; @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); qv("onRequestPermissionsResult"); switch (requestCode){ case RequestExternalStorage: mPermissionAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED; break; } if (!mPermissionAccepted) finish(); }
암호: infos
'Android' 카테고리의 다른 글
안드로이드 일정 초기화 (0) 2023.04.23 Http 파일 전송(Multipart)과 File Explorer (0) 2022.08.13 OkHttp 파일 전송(Multipart) (0) 2022.08.08 usesCleartextTraffic (0) 2022.08.08 OkHttp 접속 전송 RestfulApi (0) 2022.08.08 File 선택 화면 (deprecated startActivityForResult) (0) 2022.08.07 File 선택 화면 (0) 2022.08.07 RxAndroid (0) 2022.08.05