Reputation: 31
in oreo how to enable notification led blink without notification sound,if i disable notification sound led does not blink
Notification notification = new NotificationCompat.Builder(this)
.setLights(0xff00ff00, 3000, 100)
// .setContentTitle("title")
.setSmallIcon(R.drawable.cubs)
.setOngoing(false)
.setSound(null)
.setPriority(Notification.PRIORITY_MAX).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notification_id, notification);
Upvotes: 1
Views: 749
Reputation: 31
This is my code
`import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public abstract class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "test-channel";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel newIncidentChannel = new NotificationChannel(channelId,
"Test Channel",
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(newIncidentChannel);
}
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Test")
.setContentText("Text")
.setSound(RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
int NOTIFICATION_ID = (int) (System.currentTimeMillis()%10000);
notificationManager.notify("test", NOTIFICATION_ID, notificationBuilder.build());
}
} `
Upvotes: 0
Reputation:
From Oreo, the mechanism of NotificationChannel was introduced. You must set the channel and enable lights like this,
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Notification";
String description = "Notification";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel("someChannelID", name, importance);
mChannel.setDescription(description);
mChannel.setShowBadge(true);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(uri);
if (notificationManager != null) notificationManager.createNotificationChannel(mChannel);
Notification notification = new Notification.Builder(context, "someChannelID")
.setContentTitle(contentTitleText)
.setContentText(contentContentText)
.setNumber(1)
.setSmallIcon(whiteLogo)
.setBadgeIconType(whiteLogo)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
if (notificationManager != null) {
notificationManager.notify(notification_id, notification);
}
}
else {
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(whiteLogo)
.setLargeIcon(largeIcon)
.setContentTitle(contentTitleText)
.setContentText(contentContentText)
.setOngoing(false)
.setNumber(1)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setLights(colorPPDOrange, 1000, 2000);
.setSound(uri);
.setContentIntent(pendingIntent)
.build();
if (notificationManager != null) {
notificationManager.notify(notification_id, notification);
}
}
Upvotes: 1