簡體   English   中英

通知聲音未播放(wav文件)

[英]Notification sound not playing (wav file)

我將通知設置如下:

    Intent getBackIntent = new Intent (_context, Timers.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(_context);
    stackBuilder.addParentStack(Timers.class);
    stackBuilder.addNextIntent(getBackIntent);

    PendingIntent getBackPendingIntent = stackBuilder.getPendingIntent(C.NOTIFICATION, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri soundUri = Uri.parse("android.resuource://" + getPackageName() + "/" + R.raw.notification);

    long[] pattern = {50,50,50};

    _notificationBuilder = new NotificationCompat.Builder(_context);
    _notificationBuilder.setSmallIcon(R.drawable.icon);
    _notificationBuilder.setContentTitle("Timeneye");
    _notificationBuilder.setContentIntent(getBackPendingIntent);
    _notificationBuilder.setStyle(new NotificationCompat.InboxStyle());
    _notificationBuilder.setSound(soundUri);
    _notificationBuilder.setVibrate(pattern);
    _notificationBuilder.setLights(Color.RED, 500, 500);
    _notificationBuilder.setAutoCancel(true);

    _notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

問題是它從不播放任何聲音。
我嘗試使用相同的資源啟動MediaPlayer對象,並且它可以正常工作。

您在URI中輸入的聲音有誤。 更換:

Uri soundUri = Uri.parse("android.resuource://" + getPackageName() + "/" + R.raw.notification);

通過

Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM