Fix image file browsing on Android again. Fixes #20476

This commit is contained in:
Henrik Rydgård
2025-06-08 19:31:05 +02:00
parent 1055b83783
commit 258a3ae6db
5 changed files with 14 additions and 3 deletions
+3
View File
@@ -630,6 +630,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
return true;
case SystemRequestType::BROWSE_FOR_IMAGE:
std::thread([=] {
SetCurrentThreadName("BrowseForImage");
std::string out;
if (W32Util::BrowseForFileName(true, MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), nullptr,
FinalizeFilter(L"All supported images (*.jpg *.jpeg *.png)|*.jpg;*.jpeg;*.png|All files (*.*)|*.*||").c_str(), L"jpg", out)) {
@@ -651,6 +652,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
}
const bool load = type == SystemRequestType::BROWSE_FOR_FILE;
std::thread([=] {
SetCurrentThreadName("BrowseForFile");
std::string out;
if (W32Util::BrowseForFileName(load, MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), nullptr, filter.c_str(), L"", out)) {
g_requestManager.PostSystemSuccess(requestId, out.c_str());
@@ -663,6 +665,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::BROWSE_FOR_FOLDER:
{
std::thread([=] {
SetCurrentThreadName("BrowseForFolder");
std::string folder = W32Util::BrowseForFolder2(MainWindow::GetHWND(), param1, param2);
if (folder.size()) {
g_requestManager.PostSystemSuccess(requestId, folder.c_str());
+1 -1
View File
@@ -54,7 +54,7 @@
android:name=".PpssppActivity"
android:configChanges="locale|keyboard|keyboardHidden|navigation|uiMode"
android:theme="@style/ppsspp_style"
android:launchMode="singleInstance"
android:launchMode="singleTop"
android:exported="true">
<!-- android:screenOrientation="landscape" -->
<intent-filter>
+1
View File
@@ -56,6 +56,7 @@ struct JNIEnv {};
#include "Common/LogReporting.h"
#include "Common/Net/Resolve.h"
#include "Common/Net/URL.h"
#include "android/jni/AndroidAudio.h"
#include "Common/GPU/OpenGL/GLCommon.h"
#include "Common/GPU/OpenGL/GLFeatures.h"
@@ -1241,15 +1241,20 @@ public abstract class NativeActivity extends Activity {
Log.i(TAG, "onActivityResult: requestCode=" + requestCode + " requestId = " + requestId + " resultCode = " + resultCode);
if (resultCode != RESULT_OK || data == null) {
if (data == null) {
Log.i(TAG, "Intent data == null");
}
NativeApp.sendRequestResult(requestId, false, "", resultCode);
return;
}
try {
if (requestCode == RESULT_LOAD_IMAGE) {
Log.i(TAG, "data: " + data.toString());
Uri selectedImage = data.getData();
if (selectedImage != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Log.i(TAG, "Selected image: " + selectedImage.toString());
NativeApp.sendRequestResult(requestId, true, selectedImage.toString(), 0);
} else {
String[] filePathColumn = {MediaStore.Images.Media.DATA};
@@ -1259,9 +1264,12 @@ public abstract class NativeActivity extends Activity {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Log.i(TAG, "Selected picture path: " + selectedImage.toString());
NativeApp.sendRequestResult(requestId, true, picturePath, 0);
}
}
} else {
Log.i(TAG, "No image data received");
}
} else if (requestCode == RESULT_OPEN_DOCUMENT) {
Uri selectedFile = data.getData();
@@ -87,8 +87,7 @@ public class ShortcutActivity extends Activity {
// homescreen. Set our app as target Context. Set Main activity as
// target class. Add any parameter as data.
Intent shortcutIntent = new Intent(getApplicationContext(), PpssppActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.i(TAG, "Shortcut URI: " + uri.toString());
shortcutIntent.setData(uri);
String path = uri.toString();