0
I have a simple app to send Notifications, vibrate, and tap on receipt. On my android 4.3 it works, on another my mobile with android 9 it just touch, does not show notification and neither vibrates.
Notification method is on only one button:
public void gerarNotificacao(View view) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PendingIntent p = PendingIntent.getActivity(this, 0, new Intent(this, atividade2.class), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("Ticket Texto");
builder.setContentTitle("Título");
//builder.setContentText("Descrição");
builder.setSmallIcon(R.drawable.ic_launcher_background);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background));
builder.setContentIntent(p);
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
String[] descs = new String[]{"Descrição 1", "Descrição 2", "Descrição 3", "Descrição 4"};
for (int i = 0; i < descs.length; i++) {
style.addLine(descs[i]);
}
builder.setStyle(style);
// Vibração
Notification n = builder.build();
n.vibrate = new long[]{150, 300, 150, 600};
n.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(R.drawable.ic_launcher_background, n);
// Toque
try {
Uri som = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone toque = RingtoneManager.getRingtone(this, som);
toque.play();
} catch (Exception e) {
}
}
In the androidManifest
put this permission:
<uses-permission android:name="android.permission.VIBRATE" />
I think it’s a simple solution, thank you.