Я пытаюсь запустить службу windowleads, которая представляет собой тип диалогового окна системного оповещения (появляется, когда приложение закрыто: как плавающее окно), но не запускает службу windowleads во время трансляции.
Когда я запускаю службу из действия тогда это работает.
После изменений в поведении в Android 13 или 14+ служба переднего плана Android может быть ограничена, поскольку несколько недель я изо всех сил пытаюсь запустить службу переднего плана через широковещательный приемник на уровне API 31 или выше. .
Журналы
Caused by: java.lang.RuntimeException: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground():
WindowsLeadsService
public class WindowLeadsService extends Service {
private WindowManager windowManager;
private View dialogView;
private TextView textView3;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
dialogView = inflater.inflate(R.layout.customized_leads, null);
// Initialize MapView
textView3 = dialogView.findViewById(R.id.textview3);
// Set up the layout parameters for the window
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
// Add the view to the window
windowManager.addView(dialogView, params);
// Initialize TextViews and LinearLayouts
TextView textView2 = dialogView.findViewById(R.id.textview2);
TextView textView3 = dialogView.findViewById(R.id.textview3);
TextView textView5 = dialogView.findViewById(R.id.textview5);
TextView textView6 = dialogView.findViewById(R.id.textview6);
TextView textView7 = dialogView.findViewById(R.id.textview7);
TextView textView8 = dialogView.findViewById(R.id.textview8);
ImageView imageView1 = dialogView.findViewById(R.id.imageview1);
ImageView imageView2 = dialogView.findViewById(R.id.imageview2);
LinearLayout linear14 = dialogView.findViewById(R.id.linear14);
LinearLayout linear28 = dialogView.findViewById(R.id.linear28);
// Set click listeners
linear14.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle click
stopSelf();
String phoneNumber = "tel:+917233456780";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(phoneNumber));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (SecurityException excep) {
Toast.makeText(
getApplicationContext(),
"Something went wrong.",
Toast.LENGTH_SHORT)
.show();
}
}
});
linear28.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle click
stopSelf();
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
if (dialogView != null) {
windowManager.removeView(dialogView);
}
}
}
BroadcastReciever:
public class RebootService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, WindowLeadsService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent);
} else {
context.startService(serviceIntent);
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... l-31-or-ab
Как запустить службу переднего плана из целевого API приемника вещания уровня 31 или выше: приложение закрыто ⇐ Android
Форум для тех, кто программирует под Android
1722309218
Anonymous
Я пытаюсь запустить службу windowleads, которая представляет собой тип диалогового окна системного оповещения (появляется, когда приложение закрыто: как плавающее окно), но не запускает службу windowleads во время трансляции.
Когда я запускаю службу из действия тогда это работает.
После изменений в поведении в Android 13 или 14+ служба переднего плана Android может быть ограничена, поскольку несколько недель я изо всех сил пытаюсь запустить службу переднего плана через широковещательный приемник на уровне API 31 или выше. .
[b]Журналы[/b]
Caused by: java.lang.RuntimeException: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground():
[b]WindowsLeadsService[/b]
public class WindowLeadsService extends Service {
private WindowManager windowManager;
private View dialogView;
private TextView textView3;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
dialogView = inflater.inflate(R.layout.customized_leads, null);
// Initialize MapView
textView3 = dialogView.findViewById(R.id.textview3);
// Set up the layout parameters for the window
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
// Add the view to the window
windowManager.addView(dialogView, params);
// Initialize TextViews and LinearLayouts
TextView textView2 = dialogView.findViewById(R.id.textview2);
TextView textView3 = dialogView.findViewById(R.id.textview3);
TextView textView5 = dialogView.findViewById(R.id.textview5);
TextView textView6 = dialogView.findViewById(R.id.textview6);
TextView textView7 = dialogView.findViewById(R.id.textview7);
TextView textView8 = dialogView.findViewById(R.id.textview8);
ImageView imageView1 = dialogView.findViewById(R.id.imageview1);
ImageView imageView2 = dialogView.findViewById(R.id.imageview2);
LinearLayout linear14 = dialogView.findViewById(R.id.linear14);
LinearLayout linear28 = dialogView.findViewById(R.id.linear28);
// Set click listeners
linear14.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle click
stopSelf();
String phoneNumber = "tel:+917233456780";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(phoneNumber));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (SecurityException excep) {
Toast.makeText(
getApplicationContext(),
"Something went wrong.",
Toast.LENGTH_SHORT)
.show();
}
}
});
linear28.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle click
stopSelf();
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
if (dialogView != null) {
windowManager.removeView(dialogView);
}
}
}
[b]BroadcastReciever:[/b]
public class RebootService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, WindowLeadsService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent);
} else {
context.startService(serviceIntent);
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78808097/how-i-start-foreground-service-from-broadcast-reciever-target-api-level-31-or-ab[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия