From 258a3ae6db20a4abc79d395243401b2f4bfd967e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 8 Jun 2025 19:31:05 +0200 Subject: [PATCH] Fix image file browsing on Android again. Fixes #20476 --- Windows/main.cpp | 3 +++ android/AndroidManifest.xml | 2 +- android/jni/app-android.cpp | 1 + android/src/org/ppsspp/ppsspp/NativeActivity.java | 8 ++++++++ android/src/org/ppsspp/ppsspp/ShortcutActivity.java | 3 +-- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Windows/main.cpp b/Windows/main.cpp index 016352e2bb..5fcba58b55 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -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()); diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 1de3a43c78..bdbad60036 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -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"> diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 79ce555768..f443688932 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -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" diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 04c1c99c7f..228210cf1a 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -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(); diff --git a/android/src/org/ppsspp/ppsspp/ShortcutActivity.java b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java index 03015a1040..8a7990f2cb 100644 --- a/android/src/org/ppsspp/ppsspp/ShortcutActivity.java +++ b/android/src/org/ppsspp/ppsspp/ShortcutActivity.java @@ -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();