From 1a29fad5e1f5849bdc25a891a45abd58c65b4824 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 21 Jan 2018 15:39:21 +0100 Subject: fix NPE in shareWith intent and use FileProvider for sharing --- .../messenger/ui/ShowFullscreenMessageActivity.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java') diff --git a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java b/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java index 17fe144d7..619ab2101 100644 --- a/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShowFullscreenMessageActivity.java @@ -1,6 +1,7 @@ package de.pixart.messenger.ui; import android.app.Activity; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; @@ -33,6 +34,7 @@ import java.io.InputStream; import de.pixart.messenger.Config; import de.pixart.messenger.R; +import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.utils.ExifHelper; import static de.pixart.messenger.persistance.FileBackend.close; @@ -70,16 +72,22 @@ public class ShowFullscreenMessageActivity extends Activity { @Override public void onClick(View v) { mVideo.reset(); - shareWith(mFileUri); + shareWith(mFile); } }); } - private void shareWith(Uri mFileUri) { + private void shareWith(File mFile) { Intent share = new Intent(Intent.ACTION_SEND); - share.setType(getMimeType(mFileUri.toString())); - share.putExtra(Intent.EXTRA_STREAM, Uri.parse(mFileUri.toString())); + share.setType(getMimeType(mFile.toString())); + share.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(this, mFile)); startActivity(Intent.createChooser(share, getString(R.string.share_with))); + try { + startActivity(Intent.createChooser(share, getText(R.string.share_with))); + } catch (ActivityNotFoundException e) { + //This should happen only on faulty androids because normally chooser is always available + Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + } } public static String getMimeType(String path) { -- cgit v1.2.3