From 81ef9311b50bcff92b59164dadacfb3fd8be393e Mon Sep 17 00:00:00 2001 From: albexk Date: Thu, 31 Oct 2024 14:19:00 +0300 Subject: [PATCH] Fix importing files on TVs --- client/android/res/values-ru/strings.xml | 2 ++ client/android/res/values/strings.xml | 2 ++ .../src/org/amnezia/vpn/AmneziaActivity.kt | 23 +++++++++++-------- .../platforms/android/android_controller.cpp | 4 +++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/client/android/res/values-ru/strings.xml b/client/android/res/values-ru/strings.xml index 8bdabfc02..5e35bba51 100644 --- a/client/android/res/values-ru/strings.xml +++ b/client/android/res/values-ru/strings.xml @@ -23,4 +23,6 @@ Настройки уведомлений Для показа уведомлений необходимо включить уведомления в системных настройках Открыть настройки уведомлений + + Пожалуйста, установите приложение для просмотра файлов \ No newline at end of file diff --git a/client/android/res/values/strings.xml b/client/android/res/values/strings.xml index 5251403b9..bf8d76d1d 100644 --- a/client/android/res/values/strings.xml +++ b/client/android/res/values/strings.xml @@ -23,4 +23,6 @@ Notification settings To show notifications, you must enable notifications in the system settings Open notification settings + + Please install a file management utility to browse files \ No newline at end of file diff --git a/client/android/src/org/amnezia/vpn/AmneziaActivity.kt b/client/android/src/org/amnezia/vpn/AmneziaActivity.kt index b2c2ff71e..dd1148a39 100644 --- a/client/android/src/org/amnezia/vpn/AmneziaActivity.kt +++ b/client/android/src/org/amnezia/vpn/AmneziaActivity.kt @@ -4,6 +4,7 @@ import android.Manifest import android.annotation.SuppressLint import android.app.AlertDialog import android.app.NotificationManager +import android.content.ActivityNotFoundException import android.content.BroadcastReceiver import android.content.ComponentName import android.content.Intent @@ -563,16 +564,20 @@ class AmneziaActivity : QtActivity() { } } }.also { - startActivityForResult(it, OPEN_FILE_ACTION_CODE, ActivityResultHandler( - onAny = { - val uri = it?.data?.toString() ?: "" - Log.v(TAG, "Open file: $uri") - mainScope.launch { - qtInitialized.await() - QtAndroidController.onFileOpened(uri) + try { + startActivityForResult(it, OPEN_FILE_ACTION_CODE, ActivityResultHandler( + onAny = { + val uri = it?.data?.toString() ?: "" + Log.v(TAG, "Open file: $uri") + mainScope.launch { + qtInitialized.await() + QtAndroidController.onFileOpened(uri) + } } - } - )) + )) + } catch (_: ActivityNotFoundException) { + Toast.makeText(this@AmneziaActivity, resources.getText(R.string.tvNoFileBrowser), Toast.LENGTH_LONG).show() + } } } } diff --git a/client/platforms/android/android_controller.cpp b/client/platforms/android/android_controller.cpp index 2790eb1bd..5776cc34e 100644 --- a/client/platforms/android/android_controller.cpp +++ b/client/platforms/android/android_controller.cpp @@ -165,7 +165,9 @@ QString AndroidController::openFile(const QString &filter) [&fileName, &wait](const QString &uri) { qDebug() << "Android event: file opened; uri:" << uri; fileName = QQmlFile::urlToLocalFileOrQrc(uri); - qDebug() << "Android opened filename:" << fileName; + qDebug() << "Qt url to local file:" << fileName; + // if qt failed, try using just uri + if (fileName.isEmpty()) fileName = uri; wait.quit(); }, static_cast(Qt::QueuedConnection | Qt::SingleShotConnection));