aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/AndroidManifest.xml9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/providers/ConversationsPlusFileProvider.java20
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java25
-rw-r--r--src/main/res/xml/filepaths.xml4
5 files changed, 57 insertions, 3 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 71a0a94a..db24a8c0 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -175,6 +175,15 @@
<action android:name="android.service.chooser.ChooserTargetService" />
</intent-filter>
</service>
+ <provider
+ android:authorities="de.thedevstack.conversationsplus"
+ android:name=".providers.ConversationsPlusFileProvider"
+ android:exported="false"
+ android:grantUriPermissions="true">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/filepaths" />
+ </provider>
</application>
</manifest>
diff --git a/src/main/java/de/thedevstack/conversationsplus/providers/ConversationsPlusFileProvider.java b/src/main/java/de/thedevstack/conversationsplus/providers/ConversationsPlusFileProvider.java
new file mode 100644
index 00000000..a718b161
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/providers/ConversationsPlusFileProvider.java
@@ -0,0 +1,20 @@
+package de.thedevstack.conversationsplus.providers;
+
+import android.net.Uri;
+import android.support.v4.content.FileProvider;
+
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
+import de.thedevstack.conversationsplus.entities.DownloadableFile;
+
+/**
+ * Created by lookshe on 27.03.16.
+ */
+public class ConversationsPlusFileProvider extends FileProvider {
+
+ private static final String SCHEME = "content";
+ private static final String AUTHORITY = "de.thedevstack.conversationsplus";
+
+ public static Uri createUriForPrivateFile(DownloadableFile file) {
+ return FileProvider.getUriForFile(ConversationsPlusApplication.getAppContext(), AUTHORITY, file);
+ }
+}
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 6e766dd5..c0d09c07 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -98,7 +98,7 @@ public class FileBackend {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath() + File.separator + ConversationsPlusPreferences.imgTransferFolder() + File.separator;
}
- private static String getPrivateFileDirectoryPath() {
+ public static String getPrivateFileDirectoryPath() {
return ConversationsPlusApplication.getPrivateFilesDir().getAbsolutePath();
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index b5d1272c..1c0813a5 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -38,7 +38,9 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.providers.ConversationsPlusFileProvider;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account;
@@ -652,16 +654,35 @@ public class MessageAdapter extends ArrayAdapter<Message> {
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
return;
}
+ boolean bInPrivateStorage = false;
+ if (file.getAbsolutePath().startsWith(FileBackend.getPrivateFileDirectoryPath())) {
+ bInPrivateStorage = true;
+ }
Intent openIntent = new Intent(Intent.ACTION_VIEW);
String mime = file.getMimeType();
if (mime == null) {
mime = "*/*";
}
- openIntent.setDataAndType(Uri.fromFile(file), mime);
+ Uri uri;
+ if (bInPrivateStorage) {
+ uri = ConversationsPlusFileProvider.createUriForPrivateFile(file);
+ } else {
+ uri = Uri.fromFile(file);
+ }
+ openIntent.setDataAndType(uri, mime);
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
+ if (bInPrivateStorage) {
+ for (ResolveInfo info : infos) {
+ ConversationsPlusApplication.getAppContext().grantUriPermission(info.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ }
+ }
if (infos.size() == 0) {
- openIntent.setDataAndType(Uri.fromFile(file),"*/*");
+ openIntent.setDataAndType(uri,"*/*");
+ }
+ if (bInPrivateStorage) {
+ openIntent.putExtra(Intent.EXTRA_STREAM, uri);
+ openIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
try {
getContext().startActivity(openIntent);
diff --git a/src/main/res/xml/filepaths.xml b/src/main/res/xml/filepaths.xml
new file mode 100644
index 00000000..71062dda
--- /dev/null
+++ b/src/main/res/xml/filepaths.xml
@@ -0,0 +1,4 @@
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+ <files-path name="conversationsplus_images" path="Images/"/>
+ <files-path name="conversationsplus_files" path="files/" />
+</paths> \ No newline at end of file