1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-09-10 10:49:42 +02:00

replaced traditional file sharing with FileProvider (#174)

replaced traditional file sharing with FileProvider (fixes #173)
This commit is contained in:
Aditya Mehta 2017-11-01 09:53:19 +05:30 committed by Gregor Santner
parent 8ac5c2dee9
commit 255c6d650e
5 changed files with 40 additions and 3 deletions

View file

@ -1,10 +1,14 @@
package com.github.dfa.diaspora_android.util;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.view.View;
import com.github.dfa.diaspora_android.BuildConfig;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.web.WebHelper;
@ -70,4 +74,13 @@ public class ActivityUtils extends net.gsantner.opoc.util.ActivityUtils {
}
}
}
/**
* This method creates file sharing uri by using FileProvider
* @return
*/
public static Uri getFileSharingUri(Context context,File file) {
return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID,file);
}
}

View file

@ -42,6 +42,7 @@ import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.ui.theme.ThemeHelper;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.ActivityUtils;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
@ -228,13 +229,21 @@ public class BrowserFragment extends ThemedFragment {
// Only show share intent when Action Share Screenshot was selected
if (hasToShareScreenshot) {
Uri bmpUri = ActivityUtils.getFileSharingUri(getContext(),new File(fileSaveDirectory, fileSaveName));
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, webView.getTitle());
sharingIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
Uri bmpUri = Uri.fromFile(new File(fileSaveDirectory, fileSaveName));
sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
startActivity(Intent.createChooser(sharingIntent, getString(R.string.action_share_dotdotdot)));
PackageManager pm = getActivity().getPackageManager();
if (sharingIntent.resolveActivity(pm) != null) {
startActivity(Intent.createChooser(sharingIntent, getString(R.string.action_share_dotdotdot)));
}
} else {
// Broadcast that this file is indexable
File file = new File(fileSaveDirectory, fileSaveName);

View file

@ -39,6 +39,7 @@ import android.widget.Toast;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.service.ImageDownloadTask;
import com.github.dfa.diaspora_android.util.ActivityUtils;
import java.io.File;
@ -165,7 +166,8 @@ public class ContextMenuWebView extends NestedWebView {
new ImageDownloadTask(null, local.getPath()) {
@Override
protected void onPostExecute(Bitmap result) {
Uri myUri = Uri.fromFile(new File(local.getPath()));
Uri myUri = ActivityUtils.getFileSharingUri(context, new File(local.getPath()));
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);