从内部存储设置自定义通知声音

时间:2018-10-09 09:38:45

标签: android notifications android-notifications

我正在尝试从内部存储器播放通知声音。 首先,当有人安装应用程序时,我下载了一个文件,然后我想使用内部存储器中下载的通知声音。 以下是我正在使用的代码,但通知正在播放系统声音。

 Notification notification = new Notification.Builder(this)
            .setContentIntent(contentIntent)
            .setContentText(text)
            .setContentTitle(waktu)
            .setSmallIcon(R.mipmap.ic_logo)
            .setVibrate(new long[]{500, 1000})
            .setSound(Uri.fromFile(new File(Environment.getExternalStorageDirectory()
                                + "/Folder", Name + ".mp3")))
            .setAutoCancel(true)
            .build();

    notification.flags |=
            Notification.FLAG_ONGOING_EVENT |
                    Notification.FLAG_SHOW_LIGHTS;
    notification.ledOnMS = 300;
    notification.ledOffMS = 3000;

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Send the notification.
    mNotificationManager.notify(0, notification);

0 个答案:

没有答案