Catch the song share crash

This commit is contained in:
Karim Abou Zeid 2017-10-07 12:57:54 +02:00
commit 60aedc460f
No known key found for this signature in database
GPG key ID: 948B11DC67FD9BAF

View file

@ -56,11 +56,19 @@ public class MusicUtil {
@NonNull
public static Intent createShareSongFileIntent(@NonNull final Song song, Context context) {
return new Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName(), new File(song.data)))
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.setType("audio/*");
try {
return new Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName(), new File(song.data)))
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.setType("audio/*");
} catch (IllegalArgumentException e) {
// TODO the path is most likely not like /storage/emulated/0/... but something like /storage/28C7-75B0/...
e.printStackTrace();
Toast.makeText(context, "Could not share this file, I'm aware of the issue.", Toast.LENGTH_SHORT).show();
return new Intent();
}
}
public static void setRingtone(@NonNull final Context context, final int id) {