Skip to content

Commit

Permalink
Introduced FileProvider to fix #627 (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
LizardWithHat authored and QuantumBadger committed Nov 11, 2018
1 parent 4521793 commit a8f38c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/main/AndroidManifest.xml
Expand Up @@ -148,7 +148,17 @@
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:resource="@dimen/app_defaultsize_h" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:resource="@dimen/app_minimumsize_w" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:resource="@dimen/app_minimumsize_h" />


<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.quantumbadger.redreader.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths">
</meta-data>
</provider>
</application>

</manifest>
Expand Down
Expand Up @@ -20,6 +20,7 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
Expand Down Expand Up @@ -135,6 +136,12 @@ protected void onSuccess(
}
}

Uri sharedImage = FileProvider.getUriForFile(
context,
"org.quantumbadger.redreader.provider",
dst
);

try {
final InputStream cacheFileInputStream = cacheFile.getInputStream();

Expand All @@ -147,7 +154,7 @@ protected void onSuccess(

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + dst.getAbsolutePath()));
shareIntent.putExtra(Intent.EXTRA_STREAM, sharedImage);
shareIntent.setType(mimetype);
activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.action_share_image)));

Expand All @@ -157,7 +164,7 @@ protected void onSuccess(
}

activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.parse("file://" + dst.getAbsolutePath()))
sharedImage)
);

General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath());
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/xml/file_paths.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>

0 comments on commit a8f38c7

Please sign in to comment.