반응형
파일 퍼미션을 manifets에 넣어주어도
코드로 다시 호출해 주어야 한다.
// Storage Permissions variables
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
//persmission method.
public void verifyStoragePermissions(Activity activity) {
// Check if we have read or write permission
int writePermission =
ActivityCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
int readPermission =
ActivityCompat.checkSelfPermission(activity,
Manifest.permission.READ_EXTERNAL_STORAGE);
if (writePermission!=PackageManager.PERMISSION_GRANTED ||
readPermission!=PackageManager.PERMISSION_GRANTED) {
Log.d("paulaner80","퍼미션이 없잖아!");
ActivityCompat.requestPermissions( activity,
PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE );
}else{
Log.d("paulaner80","퍼미션이 있습니다");
examMakeDirectory();
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_EXTERNAL_STORAGE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// save file
Log.d("paulaner80","퍼미션 허락 받았습니다");
examMakeDirectory();
} else {
Log.d("paulaner80","퍼미션 거부 받았습니다");
Toast.makeText(getApplicationContext(), "PERMISSION_DENIED",
Toast.LENGTH_SHORT).show();
}
}
}
'android code' 카테고리의 다른 글
PopupWindow 예제 (0) | 2016.08.23 |
---|---|
canvas에서 selector 적용하기 (0) | 2016.08.10 |
서버에 이미지 업로드 하는 예제 (0) | 2016.07.29 |
SparseArray for 문 돌리는 법 (0) | 2016.07.27 |
벡터 드로어블 생성 (0) | 2016.06.01 |