From 789031ed5d11740b99be71da1402041a19438c99 Mon Sep 17 00:00:00 2001 From: Jagar Yousef <41321155+JagarYousef@users.noreply.github.com> Date: Sat, 27 Apr 2019 00:24:09 +0300 Subject: [PATCH] Fixing bug: share in Nougat and above --- .../VoicePlayerView.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/chatvoiceplayerlibrary/src/main/java/me/jagar/chatvoiceplayerlibrary/VoicePlayerView.java b/chatvoiceplayerlibrary/src/main/java/me/jagar/chatvoiceplayerlibrary/VoicePlayerView.java index fb79ecf..a402201 100644 --- a/chatvoiceplayerlibrary/src/main/java/me/jagar/chatvoiceplayerlibrary/VoicePlayerView.java +++ b/chatvoiceplayerlibrary/src/main/java/me/jagar/chatvoiceplayerlibrary/VoicePlayerView.java @@ -15,7 +15,10 @@ import android.media.AudioManager; import android.media.MediaPlayer; import android.net.Uri; +import android.os.Build; import android.os.Handler; +import android.os.StrictMode; +import android.support.v4.content.FileProvider; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -28,7 +31,9 @@ import java.io.IOException; import java.net.URLConnection; -public class VoicePlayerView extends LinearLayout { +import static android.os.Build.VERSION_CODES.M; + + public class VoicePlayerView extends LinearLayout { private int playPaueseBackgroundColor, shareBackgroundColor, viewBackgroundColor, seekBarProgressColor, seekBarThumbColor, progressTimeColor; @@ -235,11 +240,12 @@ public void run() { if (file.exists()){ Intent intentShareFile = new Intent(Intent.ACTION_SEND); intentShareFile.setType(URLConnection.guessContentTypeFromName(file.getName())); - intentShareFile.putExtra(Intent.EXTRA_STREAM, - Uri.parse("file://"+file.getAbsolutePath())); - //if you need - //intentShareFile.putExtra(Intent.EXTRA_SUBJECT,"Sharing File Subject); - //intentShareFile.putExtra(Intent.EXTRA_TEXT, "Sharing File Description"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ + StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); + StrictMode.setVmPolicy(builder.build()); + } + intentShareFile.putExtra(Intent.EXTRA_STREAM, + Uri.parse("file://"+file.getAbsolutePath())); context.startActivity(Intent.createChooser(intentShareFile, shareTitle)); }