안드로이드 앱 개발

Ted Permission 라이브러리 (권한) 본문

카테고리 없음

Ted Permission 라이브러리 (권한)

스텝바이스텝안드로이드 2021. 4. 14. 22:45

1. Module:gradle에 implementation

implementation 'gun0912.ted:tedpermission:2.2.3'

 

2. 객체 생성 및 메서드 추가

  PermissionListener permissionlistener = new PermissionListener() {
        @Override
        public void onPermissionGranted() {
            Toast.makeText(MainActivity.this, "Permission Granted", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onPermissionDenied(List<String> deniedPermissions) {
            Toast.makeText(MainActivity.this, "Permission Denied\n" + deniedPermissions.toString(), Toast.LENGTH_SHORT).show();
        }


    };

 

3. 권한 물을 액티비티에 다음 추가

 

  TedPermission.with(this)
    .setPermissionListener(permissionlistener)
    .setDeniedMessage("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")
    .setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)
    .check();