Merge pull request #51783 from m4gr3d/address_external_dir_access

Fix possible null pointer exception.
This commit is contained in:
Rémi Verschelde 2021-08-17 13:32:33 +02:00 committed by GitHub
commit 2ab45474fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,6 +42,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
@ -344,7 +345,11 @@ public class GodotIO {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Log.w(TAG, "Shared storage access is limited on Android 10 and higher.");
}
return Environment.getExternalStoragePublicDirectory(what).getAbsolutePath();
if (TextUtils.isEmpty(what)) {
return Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
return Environment.getExternalStoragePublicDirectory(what).getAbsolutePath();
}
} else {
return activity.getExternalFilesDir(what).getAbsolutePath();
}