瀏覽代碼

Fix opening files

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 年之前
父節點
當前提交
acdaa74e39

+ 11 - 0
src/main/java/com/owncloud/android/MainApp.java

@@ -31,6 +31,7 @@ import android.content.pm.PackageManager;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
+import android.os.StrictMode;
 import android.support.multidex.MultiDexApplication;
 import android.support.v4.util.Pair;
 import android.support.v7.app.AlertDialog;
@@ -57,6 +58,7 @@ import com.owncloud.android.utils.FilesSyncHelper;
 import com.owncloud.android.utils.PermissionUtil;
 import com.owncloud.android.utils.ReceiversHelper;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -127,6 +129,15 @@ public class MainApp extends MultiDexApplication {
             Log_OC.d("Debug", "start logging");
         }
 
+        if(Build.VERSION.SDK_INT >= 24){
+            try {
+                Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
+                m.invoke(null);
+            } catch(Exception e){
+                e.printStackTrace();
+            }
+        }
+
         initAutoUpload();
 
         // register global protection with pass code

+ 7 - 4
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -26,12 +26,9 @@ package com.owncloud.android.datamodel;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.net.Uri;
-import android.os.Build;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.support.v4.content.FileProvider;
 
-import com.owncloud.android.R;
 import com.owncloud.android.lib.common.network.WebdavUtils;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.MimeType;
@@ -278,12 +275,15 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return mLocalUri;
     }
 
+    /*
+        Partly disabled because not all apps understand paths that we get via this method for now
+     */
     public Uri getExposedFileUri(Context context) {
         if (mLocalPath == null || mLocalPath.length() == 0) {
             return null;
         }
         if (mExposedFileUri == null) {
-            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
+            /*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
                 // TODO - use FileProvider with any Android version, with deeper testing -> 2.2.0
                 mExposedFileUri = Uri.parse(
                         ContentResolver.SCHEME_FILE + "://" + WebdavUtils.encodePath(mLocalPath)
@@ -300,7 +300,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
                     Log_OC.e(TAG, "File can't be exported");
                 }
             }
+        }*/
+            return Uri.parse(ContentResolver.SCHEME_FILE + "://" + WebdavUtils.encodePath(mLocalPath));
         }
+        
         return mExposedFileUri;
     }
 

+ 1 - 1
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -120,7 +120,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         }
 
         return ParcelFileDescriptor.open(
-                new File(file.getStoragePath()), ParcelFileDescriptor.MODE_READ_ONLY);
+                new File(file.getStoragePath()), ParcelFileDescriptor.parseMode(mode));
     }
 
     @Override