ダウンロードフォルダからファイルを開くことができません。FileProvider - ダウンロードディレクトリからファイルを開く
私は、ファイルをダウンロードし、これをダウンロードフォルダに保存することができます。この後
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(descricao);
request.setTitle(titulo);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, nome);
enq = downloadManager.enqueue(request);
、私のファイルは、ディレクトリフォルダに保存された正しい:アンドロイドは>>内部共有ストレージは>>ダウンロード。 ***このパスは、ubuntuでデバイスのhdを手動で開きます。画像にはパスが表示されます。 Android HD by ubuntu folder - see the path
そして、私はこれでこのファイルを開く試してください。
downloadManager = (DownloadManager)getContext().getSystemService(DOWNLOAD_SERVICE);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enq);
Cursor c = downloadManager.query(query);
if(c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if(DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
if (uriString.substring(0, 7).matches("file://")) {
uriString = uriString.substring(7);
}
File file = new File(uriString);
Uri uriFile = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", file);
String mimetype = "application/pdf";
Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setDataAndType(uriFile, mimetype);
Intent intentChooser = Intent.createChooser(myIntent, "Choose Pdf Application");
startActivity(intentChooser);
}
}
}
}
};
getContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
私はこれでマニフェストで私のファイルプロバイダを宣言します。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
、これと:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="Download" path="Download/"/>
</paths>
しかし、ダウンロードするボタンをクリックすると、このメッセージが表示されます。「このファイルアクセスできません。場所やネットワークを確認して再試行してください「
再開:
1 - ファイルをダウンロードして保存したディレクトリのフォルダで がさ - 意図が開始されますが、ファイルではありません。 openned
3 - デバッグモードが "新しいファイル(urlString)" で私にこれを与える: - FileProvider.getUriFromFile」で
4 "urlString = /ストレージ//0 /ダウンロード/ name.pdfをエミュレート"。 .. "デバッグモードの場合:
"uriFile = content://com.example.android.parlamentaresapp.fileprovider/Download/name.pdf"
ありがとうございます。あなたはstartActivity()
とFileProvider
Uri
で使用Intent
上
'Android >>内部共有ストレージ>>ダウンロード。これはコードで使用できるファイルシステムのパスではありません。実際のフルパスを入力してください。 – greenapps