5

通知用のバイブレーションと音を設定しようとしています。何らかの理由で私にとってはうまくいきません:(これが私が試しているコードです

NotificationManager notificationManager = getNotificationManager();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        builder.setSound(alarmSound);
        builder.setVibrate(new long[] { 1000, 1000, 1000 });
        Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(title).setWhen(0)
                .setAutoCancel(true).setContentTitle(title).setPriority(Notification.PRIORITY_HIGH)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msgToDisply))
                .setContentText(msgToDisply).build();
        notificationManager.notify(NOTIFICATION, notification);
        stopSelf();

public NotificationManager getNotificationManager() {
        return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    }

そして、私は自分のマニフェストに許可を持っています

<uses-permission android:name="android.permission.VIBRATE" />

何が起こっているのか手がかりはありますか?

4

2 に答える 2

3

これは、Vibrator クラスが Notification で振動するように宣言していないためです。通知ビルダーでこのコードを入力し、選択に基づいて振動の持続時間を設定します。

    Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
 // Vibrate for 500 milliseconds
 v.vibrate(500);
于 2014-12-28T22:59:09.437 に答える