У меня есть услуга переднего плана, которая работала нормально до Android 15; Со времени Android 16 он перестал работать. Я прочитал все статьи, но не смог найти ничего, что было изменено с тех пор. < /P>
любая помощь? < /P>
Intent fullScreenIntent = new Intent(context, StopAlert.class);
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0, fullScreenIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Battery Charged")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(fullScreenPendingIntent, true); // NOT WORKING ON ANDROID 16
NotificationManagerCompat.from(context).notify(1, builder.build());
< /code>
У меня есть эти разрешения, объявленные в манифесте. < /p>
< /code>
Это служба на манифесте < /p>
< /code>
Наконец, это полная функция < /p>
public int onStartCommand(Intent intent, int flags, int startId) {
// Fix 1: Service killed by system - re-register receiver if null
if (batteryReceiver == null) {
batteryReceiver = new BroadcastReceiver() {
@SuppressLint("MissingPermission")
@Override
public void onReceive(Context context, Intent intent) {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
int batteryPercent = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB ||
plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
int selectedBatteryLevel = prefs.getInt("selectedBatteryLevel", 85);
boolean userStarted = prefs.getBoolean(USER_STARTED_KEY, DEFAULT_USER_STARTED);
boolean alertPlayed = prefs.getBoolean(ALERT_PLAYED_KEY, false);
Log.d(TAG, "onReceive: batteryPercent=" + batteryPercent + ", isPlugged=" + isPlugged +
", selectedBatteryLevel=" + selectedBatteryLevel + ", userStarted=" + userStarted +
", alertPlayed=" + alertPlayed);
if (isPlugged && batteryPercent >= selectedBatteryLevel && !alertPlayed && !userStarted) {
// Check notification permission first
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(TAG, "Missing notification permission");
return;
}
Intent fullScreenIntent = new Intent(context, StopAlert.class);
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(
context,
STOP_ACTION_NOTIFICATION_ID,
fullScreenIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, STOP_ACTION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Battery Charged")
.setContentText("Disconnect the charger")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setAutoCancel(true)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
Log.d(TAG, "onReceive: Posting full-screen notification");
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
try {
notificationManager.notify(STOP_ACTION_NOTIFICATION_ID, builder.build());
Log.d(TAG, "Notification posted successfully");
} catch (SecurityException e) {
Log.e(TAG, "Failed to post notification", e);
}
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(ALERT_PLAYED_KEY, true);
editor.putBoolean(USER_STARTED_KEY, false);
editor.apply();
} else if (!isPlugged) {
Log.d(TAG, "onReceive: Charger disconnected, resetting alertPlayed");
NotificationManagerCompat.from(context).cancel(STOP_ACTION_NOTIFICATION_ID); // Ensure notification is cancelled
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(ALERT_PLAYED_KEY, false);
editor.putBoolean(USER_STARTED_KEY, false);
editor.apply();
}
}
};
< /code>
В журналах для моего пакета я вижу это: < /p>
onReceive: Posting full-screen notification
Notification posted successfully
Подробнее здесь: https://stackoverflow.com/questions/797 ... nts-on-app
Android 16 не разрешает полноэкранные намерения в приложении ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1753247123
Anonymous
У меня есть услуга переднего плана, которая работала нормально до Android 15; Со времени Android 16 он перестал работать. Я прочитал все статьи, но не смог найти ничего, что было изменено с тех пор. < /P>
любая помощь? < /P>
Intent fullScreenIntent = new Intent(context, StopAlert.class);
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(context, 0, fullScreenIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Battery Charged")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(fullScreenPendingIntent, true); // NOT WORKING ON ANDROID 16
NotificationManagerCompat.from(context).notify(1, builder.build());
< /code>
У меня есть эти разрешения, объявленные в манифесте. < /p>
< /code>
Это служба на манифесте < /p>
< /code>
Наконец, это полная функция < /p>
public int onStartCommand(Intent intent, int flags, int startId) {
// Fix 1: Service killed by system - re-register receiver if null
if (batteryReceiver == null) {
batteryReceiver = new BroadcastReceiver() {
@SuppressLint("MissingPermission")
@Override
public void onReceive(Context context, Intent intent) {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
int batteryPercent = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB ||
plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
int selectedBatteryLevel = prefs.getInt("selectedBatteryLevel", 85);
boolean userStarted = prefs.getBoolean(USER_STARTED_KEY, DEFAULT_USER_STARTED);
boolean alertPlayed = prefs.getBoolean(ALERT_PLAYED_KEY, false);
Log.d(TAG, "onReceive: batteryPercent=" + batteryPercent + ", isPlugged=" + isPlugged +
", selectedBatteryLevel=" + selectedBatteryLevel + ", userStarted=" + userStarted +
", alertPlayed=" + alertPlayed);
if (isPlugged && batteryPercent >= selectedBatteryLevel && !alertPlayed && !userStarted) {
// Check notification permission first
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(TAG, "Missing notification permission");
return;
}
Intent fullScreenIntent = new Intent(context, StopAlert.class);
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(
context,
STOP_ACTION_NOTIFICATION_ID,
fullScreenIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, STOP_ACTION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Battery Charged")
.setContentText("Disconnect the charger")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setAutoCancel(true)
.setFullScreenIntent(fullScreenPendingIntent, true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
Log.d(TAG, "onReceive: Posting full-screen notification");
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
try {
notificationManager.notify(STOP_ACTION_NOTIFICATION_ID, builder.build());
Log.d(TAG, "Notification posted successfully");
} catch (SecurityException e) {
Log.e(TAG, "Failed to post notification", e);
}
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(ALERT_PLAYED_KEY, true);
editor.putBoolean(USER_STARTED_KEY, false);
editor.apply();
} else if (!isPlugged) {
Log.d(TAG, "onReceive: Charger disconnected, resetting alertPlayed");
NotificationManagerCompat.from(context).cancel(STOP_ACTION_NOTIFICATION_ID); // Ensure notification is cancelled
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(ALERT_PLAYED_KEY, false);
editor.putBoolean(USER_STARTED_KEY, false);
editor.apply();
}
}
};
< /code>
В журналах для моего пакета я вижу это: < /p>
onReceive: Posting full-screen notification
Notification posted successfully
Подробнее здесь: [url]https://stackoverflow.com/questions/79702414/android-16-not-allowing-full-screen-intents-on-app[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия