2017-12-10 19 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を含む構成済みルートの検索に失敗しました ' 「 :getExternalFilesDir(null)を(で必要なSTHがあったため) それはトーストせずに墜落した: "" – koralowski

+0

oを 'パス=すべきことであるが、' – greenapps

+0

ので、今ActivityNotFoundException:いいえIntent {act = android.intentを処理するアクティビティが見つかりました。action.VIEW typ = application/vnd.android.package-archive flg = 0x10000001} – koralowski

関連する問題