Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -84,6 +85,14 @@ public StoragePoint[] getAvailableStoragePoints() {
return mCachedStoragePoints.toArray(new StoragePoint[0]);
}

public boolean allowAccessFromOtherApps() {
String storagePath = MainApp.getStoragePath();

return Arrays.stream(getAvailableStoragePoints())
.anyMatch(point -> point.getPath().equals(storagePath) &&
point.getPrivacyType() == StoragePoint.PrivacyType.PUBLIC);
}

/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.datastorage.DataStorageProvider
import com.owncloud.android.files.StreamMediaFileOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down Expand Up @@ -306,15 +307,21 @@ class FileOperationsHelper(
private fun createOpenFileIntent(file: OCFile): Intent {
val storagePath = file.storagePath
val fileUri = file.getExposedFileUri(fileActivity)
val extension = storagePath.substringAfterLast('.', missingDelimiterValue = "")
val guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
val extension = storagePath.substringAfterLast('.', "")

val openFileIntent = guessedMimeType?.let { Intent(Intent.ACTION_VIEW).setDataAndType(fileUri, it) }
fun viewIntent(type: String?) = Intent(Intent.ACTION_VIEW).setDataAndType(fileUri, type)

val intent = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)?.let(::viewIntent)
?: createIntentFromShortcutFile(storagePath, extension)
?: Intent(Intent.ACTION_VIEW).setDataAndType(fileUri, file.mimeType)
?: viewIntent(file.mimeType)

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)

if (DataStorageProvider.getInstance().allowAccessFromOtherApps()) {
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
}

openFileIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
return openFileIntent
return intent
}

private fun createIntentFromShortcutFile(storagePath: String, extension: String): Intent? {
Expand Down
Loading