참고 : https://velog.io/@plashdof/%EC%95%8C%EB%9E%8C%EA%B6%8C%ED%95%9C-%EB%B6%84%EA%B8%B0%EC%B2%98%EB%A6%AC-Android-13-Android-12

 

targetSdkVersion 33

 

manifest 파일

 

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>

 

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/> // 광고

 

private val requiredPermissionList = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
    arrayOf(  // 안드로이드 13 이상 필요한 권한들
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_MEDIA_IMAGES,
        Manifest.permission.READ_MEDIA_VIDEO,
        Manifest.permission.POST_NOTIFICATIONS
    )
}else if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    arrayOf(  // 안드로이드 13 미만 마시멜로우 이상 필요한 권한들
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
    )
}

 

 

// 권한 체크 이후로직
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grandResults) {
        // READ_PHONE_STATE의 권한 체크 결과를 불러온다
        if (requestCode == 1001) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
                boolean check_result = true;
                // 모든 퍼미션을 허용했는지 체크
                for (int result : grandResults) {
                    if (result != PackageManager.PERMISSION_GRANTED) {
                        check_result = false;
                        break;
                    }
                }

                // 권한 체크에 동의를 하지 않으면 안드로이드 종료
                if (check_result == true) {
                } else {
                    finish();
                }
            }
        }
    }

Posted by 꼬장e
,