В настройках телефона «Настройки — Специальные возможности» - Управление временем - Время действовать» позволяет мне изменить тайм-аут по умолчанию для моего телефона. Однако я не хочу, чтобы пользователю приходилось это делать — я хочу, чтобы мое приложение переопределяло время ожидания по умолчанию и позволяло уведомлениям оставаться на экране дольше.
Я установил setOngoing (true) и setTimeoutAfter(120000) в моем Java-коде:
Код: Выделить всё
void createPopUpNotification(int nfNo){
if (SDK_INT >= Build.VERSION_CODES.O) {
String NOTIFICATION_CHANNEL_ID;
NOTIFICATION_CHANNEL_ID = "AMJnotifychannel";
Intent goShow = new Intent(this, DisplayActivity.class);
goShow.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, goShow, FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT );
RemoteViews expandedView=new RemoteViews(getApplicationContext().getPackageName(),R.layout.expandednotify);
expandedView.setTextViewText(R.id.placename,placeName);
NotificationManager notificationManager = (NotificationManager) this.getSystemService( NOTIFICATION_SERVICE ) ;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
if (SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "amjchannel", NotificationManager.IMPORTANCE_HIGH);
channel.shouldVibrate();
channel.enableLights(true);
channel.enableVibration(true);
channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(channel);
}
builder.setSmallIcon(R.mipmap.amjnotify);
builder.setContentIntent(pendingIntent);
builder.setCustomContentView(expandedView);
builder.setCustomBigContentView(expandedView);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setOngoing(true);
builder.setAutoCancel(true);
builder.setTimeoutAfter(120000);
builder.setChannelId( NOTIFICATION_CHANNEL_ID ) ;
notificationManager.notify(nfNo, builder.build());
}
}
Может ли кто-нибудь предложить способ заставить мое приложение переопределять время ожидания телефона по умолчанию? для уведомления?
Подробнее здесь: https://stackoverflow.com/questions/790 ... lt-timeout