mirror of
https://github.com/gsantner/dandelion
synced 2024-11-21 20:02:07 +01:00
replaced traditional file sharing with FileProvider (#174)
replaced traditional file sharing with FileProvider (fixes #173)
This commit is contained in:
parent
8ac5c2dee9
commit
255c6d650e
5 changed files with 40 additions and 3 deletions
|
@ -20,6 +20,16 @@
|
|||
android:authorities="${applicationId}.mainactivity"
|
||||
android:exported="false" />
|
||||
|
||||
<!--File provider for sharing files-->
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="${applicationId}"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_provider_paths" />
|
||||
</provider>
|
||||
<service
|
||||
android:name="com.github.dfa.diaspora_android.service.FetchPodsService"
|
||||
android:enabled="true"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
3
app/src/main/res/xml/file_provider_paths.xml
Normal file
3
app/src/main/res/xml/file_provider_paths.xml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="external_files" path="."/>
|
||||
</paths>
|
Loading…
Reference in a new issue