투케이2K

681. (Android/안드로이드) [Android SDK 33] PackageManager.getPackageInfo deprecated 대응 본문

Android

681. (Android/안드로이드) [Android SDK 33] PackageManager.getPackageInfo deprecated 대응

투케이2K 2023. 11. 7. 14:38

[개발 환경 설정]

개발 툴 : AndroidStudio

 

[소스 코드]

 

// ---------------------------------------------------------------------
// [Java 소스 코드]
// ---------------------------------------------------------------------
                    PackageInfo packageInfo = null;

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
                        packageInfo = mContext.getPackageManager().getPackageInfo(packageNames, PackageManager.PackageInfoFlags.of((long) PackageManager.GET_PERMISSIONS));
                    }
                    else {
                        packageInfo = mContext.getPackageManager().getPackageInfo(packageNames, PackageManager.GET_PERMISSIONS);
                    }
// ---------------------------------------------------------------------





// ---------------------------------------------------------------------
// [Kotin 소스 코드]
// ---------------------------------------------------------------------
                        var packageInfo:PackageInfo? = null

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
                            packageInfo = mContext.packageManager.getPackageInfo(packageNames, PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong()))
                        }
                        else {
                            packageInfo = mContext.packageManager.getPackageInfo(packageNames, PackageManager.GET_PERMISSIONS)
                        }
// ---------------------------------------------------------------------

 

반응형
Comments