jeudi 14 mai 2015

Android, issue with finding saved file on storage

I am downloading a file(PDF) from server using DownloadManager and request is request.setDestinationInExternalFilesDir(this, Environment.getDataDirectory().getPath(), filename);
The File gets save in my internal storage under "MyFiles->All files/DeviceStorage/Android/data/myPackage/files/data/"

For opening the saved file i use the following code

File sdCardRoot = new File(Environment.getDataDirectory().getPath());
if(sdCardRoot.exists()){
    for (File f : sdCardRoot.listFiles()) {
        if (f.isFile()){
            name1 = f.getName();

            String path = f.getPath();

            Log.e("UriFile", ""+Uri.parse(path));
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(path), "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            startActivity(intent);
        }}

But it shows document cannot be opened, But i can see the file in the location and can open it directly not from my app. I have a SD card inserted and there is a similar folder structure created in sdcard aswell, i guess while opening the file it searches the folder on SDCARD not my internal storage, how to solve this. TIA

Aucun commentaire:

Enregistrer un commentaire