2017-09-09 14 views
-2

API (18)에 충돌 나는 다음과 같은 코드가 있습니다.FileWriter fw = 새 FileWriter (vcf 파일); 그것은 새로운 API에 대한 잘 작동하지만</p> <pre><code>File vcfFile = new File(this.getExternalFilesDir(null), "generated.vcf"); FileWriter fw = new FileWriter(vcfFile); fw.write("BEGIN:VCARDrn"); ... </code></pre> <p>API (18)에 충돌 :

Caused by: java.io.FileNotFoundException: /generated.vcf: open failed: EROFS (Read-only file system) 

나는이 이유라고 생각하지만, 나는 해결 방법을 찾을 수 없습니다. 그것은 응용 프로그램의 주요 기능입니다, 그래서 그것을 제거하는 것은 나를 위해 정말 옵션이 아닙니다.

+1

당신이 매니페스트의 권한 부분을 게시 할 수 있습니까? – FWeigl

+0

@Ascorbin 거기에 권한이 없습니다, 응용 프로그램은 새로운 API를 적어도 필요가 없습니다. 어떤 권한을 구현해야합니까? – JDoeDoeDoeJ

답변

1

을 보유해야 Android 4.3 이상에서 getExternalFilesDir()에 글을 쓸 수 있습니다. Android 4.4 이상에서만 해당 위치를 건너 뛸 수 있습니다.

0

외부 저장소에 쓸 수있는 권한이 필요합니다. 새 API를 사용하려면 manifest에 권한을 선언하고 런타임 중에 권한을 요청해야합니다.

// Here, thisActivity is the current activity 
if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.WRITE_EXTERNAL_STORAGE) 
     != PackageManager.PERMISSION_GRANTED) { 

    // Should we show an explanation? 
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
      Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 

     // Show an explanation to the user *asynchronously* -- don't block 
     // this thread waiting for the user's response! After the user 
     // sees the explanation, try again to request the permission. 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 
       MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); 

     // MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE is an 
     // app-defined int constant. The callback method gets the 
     // result of the request. 
    } 
} 
당신은 자세한 내용은이 링크를 확인하실 수 있습니다

: https://developer.android.com/training/permissions/requesting.html