1
は、私は、ユーザーに通知を送信するために使用していたコードです:Androidの通知の下に複数のデフォルト
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Secure Mail")
.setContentText("New Secure Mail Received")
.setAutoCancel(true)
.setOnlyAlertOnce(true);
/*
.addAction(R.drawable.ic_reply_white_24dp, "Reply", contentIntent)
.addAction(R.drawable.ic_reply_all_white_24dp, "Reply All", contentIntent)
.addAction(R.drawable.ic_forward_white_24dp, "Forward", contentIntent);
*/
builder.setContentIntent(contentIntent);
builder.setAutoCancel(true);
builder.setOnlyAlertOnce(true);
if (ringtone.equals("")) {
Log.d(TAG, "Default Sound");
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(soundUri);
} else if (!ringtone.equals("Silent")) {
Log.d(TAG, "Selected sound: " + Uri.parse(ringtone));
//Uri currentRintoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE);
Uri currentRintoneUri = Uri.parse(ringtone);
builder.setSound(currentRintoneUri);
}
//builder.setLights(Color.BLUE, 500, 500);
if (vibrate.equals("true")) {
Log.d(TAG, "Vibrate is enabled");
//long[] pattern = {500, 500, 500, 500, 500, 500, 500, 500, 500};
//builder.setVibrate(pattern);
builder.setDefaults(Notification.DEFAULT_VIBRATE);
}
builder.setStyle(new NotificationCompat.InboxStyle());
/*
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
*/
builder.setDefaults(Notification.FLAG_AUTO_CANCEL);
builder.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE);
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
manager.notify(1, builder.build());
私は、複数のデフォルト値を持ってできるようにする必要があります(バイブレーション、自動キャンセルと一度警告)が、それが表示されます最後のもの(アラートは1回のみ)は動作し、他のものは動作しません。
通知オブジェクトを使用してフラグを設定しようとしました(これは、振動、自動キャンセル、自分のデバイスで一度警告するように見えましたが、他のユーザーは今通知が届いていないと報告していました)。
したがって、現在のコードを使用することはできますが、振動、自動キャンセル、アラートの3つのデフォルトを設定するにはどうすればよいですか?
デフォルトの組み合わせに '|'演算子を使用しましたか? –
@KNeerajLal、ありがとう! 'builder.setDefaults(Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE); ' これは動作するようです。 –
あなたが答えを見つけたことをうれしく思います。私は答えを投稿すべきですか? –