add file provider to share files on android n

This commit is contained in:
Daniel Gultsch 2016-08-25 22:41:33 +02:00
parent b0cdc2745c
commit 910b38ec13
4 changed files with 94 additions and 70 deletions

View file

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="eu.siacs.conversations"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="eu.siacs.conversations">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@ -78,8 +77,10 @@
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:host="conversations.im" />
<data android:pathPrefix="/i/" />
@ -90,19 +91,19 @@
<activity
android:name=".ui.WelcomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"/>
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".ui.MagicCreateActivity"
android:label="@string/create_account"
android:screenOrientation="portrait"
android:launchMode="singleTask"/>
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".ui.SetPresenceActivity"
android:label="@string/change_presence"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="stateHidden|adjustResize"
android:launchMode="singleTask"/>
android:label="@string/change_presence"
android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name=".ui.SettingsActivity"
android:label="@string/title_activity_settings" />
@ -163,6 +164,7 @@
<data android:mimeType="image/*" />
</intent-filter>
<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value=".services.ContactChooserTargetService" />
@ -184,13 +186,27 @@
android:value="eu.siacs.conversations.ui.SettingsActivity" />
</activity>
<activity android:name="com.soundcloud.android.crop.CropImageActivity" />
<service android:name=".services.ExportLogsService" />
<service android:name=".services.ContactChooserTargetService"
<service
android:name=".services.ContactChooserTargetService"
android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
<intent-filter>
<action android:name="android.service.chooser.ChooserTargetService" />
</intent-filter>
</service>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="eu.siacs.conversations.files"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>

View file

@ -699,6 +699,7 @@ public class XmppConnectionService extends Service {
private void directReply(Conversation conversation, String body) {
Message message = new Message(conversation,body,conversation.getNextEncryption());
message.markUnread();
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
getPgpEngine().encrypt(message, new UiCallback<Message>() {
@Override

View file

@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.content.FileProvider;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
@ -715,7 +716,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (mime == null) {
mime = "*/*";
}
openIntent.setDataAndType(Uri.fromFile(file), mime);
Uri uri = FileProvider.getUriForFile(activity,"eu.siacs.conversations.files",file);
openIntent.setDataAndType(uri, mime);
openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
if (infos.size() == 0) {

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external" path="/"/>
</paths>