cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Plugin is not listing documents(.pdf,.docx etc)

Open GAGANsinghmsitece opened this issue 4 years ago • 9 comments
trafficstars

Bug Report

Problem

What is expected to happen?

Plugin should log directories while log all the pdf files present in internal storage(android) on android.

What does actually happen?

It list files like .jpeg,.mp3,.mp4 but do not list any document like .pdf,.docx

Information

I tried following code on one UI 3.0(android 11):-

let readfiles={
       'read':function(path){
	  window.resolveLocalFileSystemURL(path,
		function (fileSystem) {
			var reader = fileSystem.createReader();
			reader.readEntries(
				function (entries) {
					console.log(entries);
					for(var i=0;i<entries.length;i++)
						if(entries[i].isDirectory===true)
							readfiles.read(entries[i].nativeURL);
						else{
							if(entries[i].nativeURL.endsWith(".pdf")===true)
								console.log(entries[i].nativeURL);
						}
				},
				function (err) {
					console.log(err);
				});
		}, function (err) {
			console.log(err);
		}
	);
      }
    }
    readfiles.read(cordova.file.externalRootDirectory);

Environment, Platform, Device

I am building this project on ubuntu 20.04LTS and the device I used for testing is Galaxy M31 with One UI 3.0(android 11).

Version information

Cordova: 10.0.0 cordova-plugin-file: 6.0.2

Checklist

  • [x ] I searched for existing GitHub issues
  • [ x] I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above

GAGANsinghmsitece avatar Jan 31 '21 16:01 GAGANsinghmsitece

Which Android version (or API level) are you using?

jfoclpf avatar Mar 26 '21 22:03 jfoclpf

I'm using API level 30, for now I solved this error using requestLegacyExternalStorage

GAGANsinghmsitece avatar Mar 27 '21 07:03 GAGANsinghmsitece

Could you kindly tell me how exactctly did you use requestLegacyExternalStorage?

In config.xml? How? Thanks

jfoclpf avatar Mar 27 '21 11:03 jfoclpf

@GAGANsinghmsitece have you tested in Android 11? I don't think that flag works in Android 11, just in Android 10

More information here: https://github.com/apache/cordova-plugin-file/issues/426

jfoclpf avatar Mar 27 '21 11:03 jfoclpf

I tried this in one ui 3.0 which is based on android 11 and it works. If you looked at https://developer.android.com/about/versions/11/privacy/storage . It says,

Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.

Which means if your app targets API level 29, it can still request access to all files in android 11 using the flag. Still, it's a temporary hack as in future version, it will cause more trouble. Hope this plugin include these changes in future versions. I created the app in feb 2021 and it is currently working Most probably, you haven't asked for permission before accessing file system

GAGANsinghmsitece avatar Mar 28 '21 04:03 GAGANsinghmsitece

Still facing the same issue for pdf files , any solution?

rejneesh1 avatar Jun 10 '21 11:06 rejneesh1

Any update?

victorvhpg avatar Jul 14 '21 15:07 victorvhpg

As of API 29, scoped storage was introduced. API 29 offered a flag to opt out of scoped storage, but in API 30, that flag is ignored and scoped storage is always enforced.

By default, without the READ_EXTERNAL_STORAGE permission, any files that is not created by your app will be hidden (e.g. attempting to read them will result in a file not found error). I have a fork that might help with this issue.

Listing directories never checked/request the READ_EXTERNAL_STORAGE permission, and I have a PR that addresses this.

breautek avatar Sep 27 '21 13:09 breautek

As of API 29, scoped storage was introduced. API 29 offered a flag to opt out of scoped storage, but in API 30, that flag is ignored and scoped storage is always enforced.

By default, without the READ_EXTERNAL_STORAGE permission, any files that is not created by your app will be hidden (e.g. attempting to read them will result in a file not found error). I have a fork that might help with this issue.

Listing directories never checked/request the READ_EXTERNAL_STORAGE permission, and I have a PR that addresses this.

How do I use your "FORK"?

danicarla avatar Nov 10 '21 18:11 danicarla

How do I use your "FORK"?

My branch has been deleted since then, but my PR was merged in and released in v7.0.0

However, Android Scoped Storage makes it so you cannot discover files that wasn't written by your app. Listing files in the external directories (e.g. inside /storage/emulated/0/ or /sdcard/) will only list files that was written by your app. Other files written by other apps will not be listed anymore.

For this reason, I'm closing as not a bug.

breautek avatar Dec 19 '22 03:12 breautek