3

Some folders in my phone storage include files like this:

  • dzG럫saᡑῑ.sg
  • 존Ὣ 졼).sg

So when I try to read files from this folder with File.listFiles() function my app crashes:

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte ...... string: 'dzG럫saᡑῑ.sg'

I found out which app creates them, but it doesn't matter, for example if other users would have similar files on their phone memory, I can't just ask them to remove it

I just want to avoid app crashing

Even try...catch doesn't help (cause error with JNI/LINUX/C++):

    try {
        ... = dir.listFiles();
    } catch (RuntimeException e) {
        //
    }

So how am I supposed to solve this problem?

Same issue here File.listFiles crashes for invalid UTF-8 characters

But answer with signing apk isn't good, how is it even related to this issue? Any other solutions?

And seems debug apk is signed automatically (with debug certificate):

When running or debugging your project from the IDE, Android Studio automatically signs your APK with a debug certificate generated by the Android SDK tools. The first time you run or debug your project in Android Studio, the IDE automatically creates the debug keystore and certificate in $HOME/.android/debug.keystore, and sets the keystore and key passwords.

user924
  • 8,146
  • 7
  • 57
  • 139

1 Answers1

0

As a workaround for API>=26 you can use DirectoryStream

Erik
  • 1
  • https://docs.oracle.com/javase/7/docs/api/java/nio/file/DirectoryStream.html – Erik Jul 26 '20 at 23:16
  • you should quote some of the info from that site in case it ever gets deleted. On your answer, hit the edit button and type whatever is related to your answer and also include the link. – Rojo Jul 28 '20 at 12:55