Ich bin neu in android. Und ich versuche, eine Benachrichtigung mit einer benutzerdefinierten Sounddauer zu erstellen. Ich habe eine Menge Apps mit dieser Funktion gesehen, aber ich kann nicht verstehen, wie man es am nützlichsten macht.Wie man Benachrichtigungssounddauer im richtigen Weg einstellt Android
Für meine Anmeldung verwende ich BroadcastReceiver
:
public class NotificationAlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
setNotification(context);
}
private void setNotification(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context,
(int) System.currentTimeMillis(), intent, 0);
Notification notification = new Notification.Builder(context).
setTicker("Hi!").
setAutoCancel(true).
setContentTitle("Bla bla lba!").
setContentText("Hi hi!").
setSmallIcon(R.mipmap.ic_launcher).
setContentIntent(pendingIntent).build();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_INSISTENT;
notificationManager.notify((int) System.currentTimeMillis(), notification);
}
}
Dank!