0

通知ビルダーを使用していて、音、振動、光が必要です。振動と光は正常に機能しますが、音は再生されません。ここで多くの解決策を試しましたが、それらのほとんどは非推奨バージョン用です。以下のコードでは、私が何をしているかを見ることができます。alamsound と sound の両方を試しましたが、どれもうまくいきませんでした。許可が必要ですか?

    public void createTestNotification(){
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    long[] vibrate = { 0, 100, 200, 300 };
    NotificationManager nm= (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    Uri sound = Uri.parse("android.resource://com.uks.uksnavigation/" + R.raw.notification);


    Intent intent = new Intent(this.getActivity(), MainActivity.class);
    intent.setAction("nachricht");
    PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);

    Notification.Builder mBuilder =
            new Notification.Builder(getActivity())
    .setContentIntent(pIntent)
            .setSmallIcon(R.drawable.ic_stat_mail_aktiv)
            .setContentTitle("New Message")
            .setContentText("Nachrichten text text text")
            .setSound(sound)
            .setVibrate(vibrate)
            .setLights(Color.BLUE, 500, 500);

    nm.notify(1, mBuilder.build());     


}
4

1 に答える 1

1

を使用しUri.parse("android.resource://com.uks.uksnavigation/raw/notification")ます。

于 2013-10-18T04:09:22.523 に答える