mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
Android: Catch some exceptions
This commit is contained in:
parent
f6fb711d34
commit
21686a6a93
@ -1118,30 +1118,39 @@ public abstract class NativeActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
if (requestCode == RESULT_LOAD_IMAGE) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
NativeApp.sendMessage("bgImage_updated", selectedImage.toString());
|
||||
} else {
|
||||
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
NativeApp.sendMessage("bgImage_updated", picturePath);
|
||||
try {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
NativeApp.sendMessage("bgImage_updated", selectedImage.toString());
|
||||
} else {
|
||||
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
NativeApp.sendMessage("bgImage_updated", picturePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Exception receiving image: " + e.toString());
|
||||
}
|
||||
} else if (requestCode == RESULT_OPEN_DOCUMENT) {
|
||||
Uri selectedFile = data.getData();
|
||||
if (selectedFile != null) {
|
||||
// Grab permanent permission so we can show it in recents list etc.
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
getContentResolver().takePersistableUriPermission(selectedFile, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
try {
|
||||
// Grab permanent permission so we can show it in recents list etc.
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
getContentResolver().takePersistableUriPermission(selectedFile, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Exception getting permissions for document: " + e.toString());
|
||||
}
|
||||
// Even if we got an exception getting permissions, try to pass along the file. Maybe this version of Android
|
||||
// doesn't need it.
|
||||
Log.i(TAG, "Browse file finished:" + selectedFile.toString());
|
||||
NativeApp.sendMessage("browse_fileSelect", selectedFile.toString());
|
||||
}
|
||||
@ -1150,7 +1159,13 @@ public abstract class NativeActivity extends Activity {
|
||||
if (selectedDirectoryUri != null) {
|
||||
String path = selectedDirectoryUri.toString();
|
||||
Log.i(TAG, "Browse folder finished: " + path);
|
||||
getContentResolver().takePersistableUriPermission(selectedDirectoryUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
try {
|
||||
getContentResolver().takePersistableUriPermission(selectedDirectoryUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Exception getting permissions for document: " + e.toString());
|
||||
}
|
||||
// Even if we got an exception getting permissions, try to pass along the file. Maybe this version of Android
|
||||
// doesn't need it. If we can't access it, we'll fail in some other way later.
|
||||
DocumentFile documentFile = DocumentFile.fromTreeUri(this, selectedDirectoryUri);
|
||||
Log.i(TAG, "Document name: " + documentFile.getUri());
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user