Catch the song share crash
This commit is contained in:
parent
fa07f612cf
commit
60aedc460f
1 changed files with 13 additions and 5 deletions
|
|
@ -56,11 +56,19 @@ public class MusicUtil {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent createShareSongFileIntent(@NonNull final Song song, Context context) {
|
public static Intent createShareSongFileIntent(@NonNull final Song song, Context context) {
|
||||||
return new Intent()
|
try {
|
||||||
.setAction(Intent.ACTION_SEND)
|
|
||||||
.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName(), new File(song.data)))
|
return new Intent()
|
||||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
.setAction(Intent.ACTION_SEND)
|
||||||
.setType("audio/*");
|
.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) {
|
public static void setRingtone(@NonNull final Context context, final int id) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue