0

通知を受け取ったときに raw フォルダから曲を開始することはできますか? このコードを試して、曲「アラート」を開始しましたが、何も起こりません。

NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.beatdanger,
        "Your friend is in danger!!!", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.sound = Uri.parse("R.raw.alert");


Intent intent1 = new Intent("wael.ilahi.pfe.SMSRECEIVERESULT");
intent1.putExtra("coordination", str);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
        intent1, 0);
notification.setLatestEventInfo(context, "Help your friend !!",
        str, pendingIntent);
notificationManager.notify(0, notification);
4

1 に答える 1

1

通知に関する Android ドキュメンテーションの「サウンドの追加」の章を参照してください。

あなたの問題は、notification-object に間違ったURIを与えているようです:"R.raw.alert"は無効です。

代わりに、ディレクトリに保存されているファイルへの URI を取得する必要がある場合は、次のres/raw/パターンを使用"android.resource://" + getPackageName() + "/" + R.raw.your_raw_fileします: ここで説明されているように: How to play videos in android from assets folder or raw folder?

于 2012-04-10T23:13:38.743 に答える