Fix possible null pointer exception.

(cherry picked from commit e2bcdad43b)
This commit is contained in:
ne0fhyk 2021-08-16 23:14:10 -07:00 committed by Rémi Verschelde
parent c55be95364
commit a9bffd5878
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -43,6 +43,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;
@ -484,7 +485,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();
}