2017-12-10 3 views
0

setDestinationInExternalFilesDir (this, "/ download", "app-debug.apk"); 왜 이것이 내부 저장소에 저장됩니까?내부 저장소 읽기 쓰기

및 /data/data/com.example.xxx/files/download/app-debug.apk

downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
Uri uri = Uri.parse("http://"); 
DownloadManager.Request request = new DownloadManager.Request(uri); 
request.setDestinationInExternalFilesDir(this, "/download", "app-debug.apk"); 
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
Long reference = downloadManager.enqueue(request); 

File imagePath = new File(getFilesDir(), "download"); 
File newFile = new File(imagePath, "app-debug.apk"); 
CharSequence text1 = "no file"; 
Toast toast1 = Toast.makeText(getApplicationContext(), newFile.getAbsolutePath()+"can't find file ", Toast.LENGTH_SHORT); 

if(!newFile.exists()){toast1.show(); return false;} 
Uri uri2 = FileProvider.getUriForFile(this,"com.example.xxx",newFile); 
Intent i = new Intent(); 
i.setAction(android.content.Intent.ACTION_VIEW); 
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
i.setData(uri2); 
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
i.setType("application/vnd.android.package-archive"); 
startActivity(i); 

제공 경로

<?xml version="1.0" encoding="utf-8"?> 
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
<!--<external-path name="external_files" path="."/>--> 
<files-path 
name="tlumacz1" 
path="download"/> 
</paths> 

매니페스트가 포함되어 구성 루트를 찾는 데 실패하는 이유

<provider 
     android:name="android.support.v4.content.FileProvider" 
     android:authorities="com.example.xxx" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/provider_paths"/> 
    </provider> 

mby 내부 저장소 또는 sth에 외부 저장소가 있습니까?

+0

다음 코드를 추가하십시오 :'if (! newFile.exists()) {Toast (... file does not exist ..); return;}'. 보고 해주세요. – greenapps

+0

getFilesDir()의 경우 를 지정해야합니다. 어쩌면 그것의 전화 된 <파일 경로. 문서를 참조하십시오. – greenapps

+0

시도해 보았습니다. – koralowski

답변

0

getFilesDir()getExternalFilesDir()으로 바꿉니다.

그리고 공급자 경로를 수정하십시오. 당신이 원래 가진 것처럼.

+0

이 /storage/emulated/0/Android/data/com.example.xxx/files/download/app-debug.apk 포함 구성 루트를 찾지 못했습니다 '<외부 경로 이름 = "tlumacz1" 경로 = getExternalFilesDir (NULL을)에 STH가 필요했기 때문에() 그것은 토스트없이 추락 : "다운로드"/> ' 나는 그것을 좋아했다 – koralowski

+0

O ='경로해야한다는' – greenapps

+0

이제 ActivityNotFoundException ".": 없음 인 텐트 {act = android.intent.action.VIEW typ = application/vnd.android.package-archive flg = 0x10000001} – koralowski