Reputation:
I have a music player app that I'm developing just to learn, and I wanted to test it on my phone. If I run the app on the emulator it works like a charm, but if I use my real phone for debugging then it stops at this part:
loadFiles(Environment.getExternalStorageDirectory().getAbsolutePath() + "/");
public void loadFiles(String path) {
Log.d(TAG, "loadFiles");
File f = new File(path);
File[] files = f.listFiles();
if (files != null) {
... //Wont run
}
}
So I added another Log.d
before the if to see what's wrong and turns out that the files
is null. No errors, and works in the emulator.
App written in API 21, the phone is Xiaomi Redmi Note 7 Pro, android 10, I have USB debugging enabled.
Log after run (Errors, full log here):
2021-05-20 20:40:51.713 20237-20237/? I/rox.musicplaye: Late-enabling -Xcheck:jni
2021-05-20 20:40:51.738 20237-20237/? E/rox.musicplaye: Unknown bits set in runtime_flags: 0x8000
2021-05-20 20:40:52.059 20237-20237/com.wotrox.musicplayer I/Perf: Connecting to perf service.
2021-05-20 20:40:52.074 20237-20237/com.wotrox.musicplayer I/FeatureParser: can't find lavender.xml in assets/device_features/,it may be in /system/etc/device_features
2021-05-20 20:40:52.088 20237-20237/com.wotrox.musicplayer E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2021-05-20 20:40:52.078 20237-20237/com.wotrox.musicplayer W/rox.musicplayer: type=1400 audit(0.0:54557): avc: denied { read } for name="u:object_r:vendor_displayfeature_prop:s0" dev="tmpfs" ino=13065 scontext=u:r:untrusted_app:s0:c155,c258,c512,c768 tcontext=u:object_r:vendor_displayfeature_prop:s0 tclass=file permissive=0
2021-05-20 20:40:52.094 20237-20268/com.wotrox.musicplayer E/Perf: Fail to get file list com.wotrox.musicplayer
2021-05-20 20:40:52.095 20237-20268/com.wotrox.musicplayer E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-05-20 20:40:52.096 20237-20268/com.wotrox.musicplayer E/Perf: Fail to get file list com.wotrox.musicplayer
2021-05-20 20:40:52.096 20237-20268/com.wotrox.musicplayer E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
Upvotes: 0
Views: 161
Reputation:
Found the problem!
Since Android 10 you have to write
android:requestLegacyExternalStorage="true"
into the Manifest file
Upvotes: 0
Reputation: 908
Try to use multidexEnabled
in your build.gradle
:
defaultConfig {
multiDexEnabled true
}
clean , build and run
If that does not work try to enable USB Debugging Mode. Here's a manual
you might be missing some SDK's, but this is unlikely.
Upvotes: 1