2017-03-16 7 views
0

안녕하세요 모든 삼성 장치에서 SDCARD에 쓸 수 없습니다. 하지만 api, dir.canWrite()는 실패합니다. 즉, 그 경로에 쓸 수 없다는 뜻입니다. 똑같은 동작을 moto x에서 시도했습니다.안드로이드 : 나는 마시 멜로와 삼성 장치에서의 sdcard에 폴더를 만들려고하고</p> <p>, 마시멜로

어떤 하나 pls는 저에게

업데이트를 도와 :

나는 모든 매니페스트의 권한도 실행 권한에 대해 코드가 있습니다.

매니페스트 파일 :

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

런타임 권한 코드 : 나는 삼성 장치에이 코드를 호출 할 때마다

private final int WRITE_STORAGE_CODE = 10; 
@TargetApi(23) 
public boolean isStoragePermissionGrantedForWriteStorage() { 
    if (Build.VERSION.SDK_INT >= 23) { 
     if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) 
       == PackageManager.PERMISSION_GRANTED) { 
      Log.v(TAG,"Permission is granted"); 
      return true; 
     } else { 

      Log.v(TAG,"Permission is revoked"); 
      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_STORAGE_CODE); 
      return false; 
     } 
    } 
    else { //permission is automatically granted on sdk<23 upon installation 
     Log.v(TAG,"Permission is granted"); 
     return true; 
    } 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, 
     String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case WRITE_STORAGE_CODE: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 
       && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       File dir = new File("/storage/6A6B-1CEF/"); // This is the memory card location. 

       if(dir.canWrite()) 
       { 
        Log.d("Activity", can write here!!); 
       }else{ 
        Log.d("Activity", oops!!!!, can't write here!!);     } 
      } else { 

       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
       Log.d("Activity", permission denied); 
      } 
      return; 
     } 

     // other 'case' lines to check for other 
     // permissions this app might request 
    } 
} 

그래서, 그 위치에의 인쇄를 쓸 수 있습니다. 그러나 동일한 코드를 사용하여 Moto x 장치에 쓸 수 있습니다.

참고 : 나는 산들은 "내부 저장"또는 "휴대용 저장 '중 하나와 같은 메모리 카드를 가지고있는 옵션을 가지고 읽었습니다

. 나는 모바일 (삼성과 모토)에서 이식 가능한 메모리를 선택했지만이 코드는 삼성에서만 실패합니다.

+1

런타임 권한을 추가 했습니까? – rafsanahmad007

+1

Marshmallow에서 파일 작업을 수행하기 전에 사용 권한을 요청해야합니다. 그렇지 않으면 SecurityException이 발생합니다. –

+0

'하지만 api, dir.canWrite()는 실패합니다. ' 그렇게 생각하지 마십시오. 이 함수는 쓸 수없는 경우 false를 반환합니다. – greenapps

답변

0

매니페스트 파일에 권한을 추가 했습니까?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
+0

예, 저도 .. 질문을 업데이트했습니다. @ M.Saad Lakhan –