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

View file

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

View file

@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.content.FileProvider;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
@ -715,7 +716,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (mime == null) { if (mime == null) {
mime = "*/*"; 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(); PackageManager manager = activity.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0); List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
if (infos.size() == 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>