[Libreoffice-commits] online.git: android/app

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Mar 11 14:57:41 UTC 2020


 android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java |   13 ++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

New commits:
commit fb27d9a79679f6aac5f2199163d5ba3e6421f2e5
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Mar 9 11:25:52 2020 +0100
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Wed Mar 11 15:57:22 2020 +0100

    android: fix opening document because activity is not found
    
    Opening a document with Intent.ACTION_OPEN_DOCUMENT is only
    supported with Android SDK >= 19, so for complete support we need
    to add a fallback to Intent.ACTION_GET_CONTENT. Additionally if
    the activity Intent.ACTION_OPEN_DOCUMENT is not found for whatever
    reason, also try to start it with the fallback.
    
    Change-Id: I0e28a3bb038a5d44716856e5c015223933c6de6b
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90210
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 10652f005..c9989069a 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -11,6 +11,7 @@ package org.libreoffice.androidapp.ui;
 
 import android.Manifest;
 import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
@@ -660,8 +661,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
     private void openDocument() {
         collapseFabMenu();
 
-        Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
-
+        Intent i = new Intent();
         i.addCategory(Intent.CATEGORY_OPENABLE);
 
         // set only the allowed mime types
@@ -724,6 +724,15 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         // TODO and that should default to Context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
         //i.putExtra(DocumentsContract.EXTRA_INITIAL_URI, previousDirectoryPath);
 
+        try {
+            i.setAction(Intent.ACTION_OPEN_DOCUMENT);
+            startActivityForResult(i, OPEN_FILE_REQUEST_CODE);
+            return;
+        } catch (ActivityNotFoundException exception) {
+            Log.w(LOGTAG, "Start of activity with ACTION_OPEN_DOCUMENT failed (no activity found). Trying the fallback.");
+        }
+        // Fallback
+        i.setAction(Intent.ACTION_GET_CONTENT);
         startActivityForResult(i, OPEN_FILE_REQUEST_CODE);
     }
 


More information about the Libreoffice-commits mailing list