android-service

Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

偶尔善良 提交于 2019-12-27 09:03:09
问题 On application launch, app starts the service that should to do some network task. After targeting API level 26, my application fails to start service on Android 8.0 on background. Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=my.app.tt/com.my.service }: app is in background uid UidRecord{90372b1 u0a136 CEM idle procs:1 seq(0,0,0)} as I understand it related to: Background execution limits The startService() method now throws an IllegalStateException if

Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

情到浓时终转凉″ 提交于 2019-12-27 09:03:02
问题 On application launch, app starts the service that should to do some network task. After targeting API level 26, my application fails to start service on Android 8.0 on background. Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=my.app.tt/com.my.service }: app is in background uid UidRecord{90372b1 u0a136 CEM idle procs:1 seq(0,0,0)} as I understand it related to: Background execution limits The startService() method now throws an IllegalStateException if

background service has stopped on miui rom

人盡茶涼 提交于 2019-12-25 19:46:51
问题 I am developing a background services and in OnDestroy Method, I've called an intent to start my services again. I'ts not started again on miui rom (Xiaomi mobile and huawei mobile). How do I handle this? public class NotificationsService extends Service { @Override public void onCreate() { ApplicationLoader.postInitApplication(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public IBinder onBind(Intent intent) { return null;

background service has stopped on miui rom

倖福魔咒の 提交于 2019-12-25 19:46:10
问题 I am developing a background services and in OnDestroy Method, I've called an intent to start my services again. I'ts not started again on miui rom (Xiaomi mobile and huawei mobile). How do I handle this? public class NotificationsService extends Service { @Override public void onCreate() { ApplicationLoader.postInitApplication(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public IBinder onBind(Intent intent) { return null;

How to install an APK from Service

☆樱花仙子☆ 提交于 2019-12-25 18:47:13
问题 I have a BroadcastReceiver , I download an apk from the server, when I catch action DownloadManager.ACTION_DOWNLOAD_COMPLETE I install the apk using activity.startActivityForResult(my_intent, REQUEST_CODE) Now I want to move this logic in a Service and also install the apk, but inside the service I don't have a Activity, I can to cast context to Activity obtained from getapplicationcontext(), but I catch the error that context can't be casted to com.android.Activity How I can to run

How to install an APK from Service

吃可爱长大的小学妹 提交于 2019-12-25 18:47:00
问题 I have a BroadcastReceiver , I download an apk from the server, when I catch action DownloadManager.ACTION_DOWNLOAD_COMPLETE I install the apk using activity.startActivityForResult(my_intent, REQUEST_CODE) Now I want to move this logic in a Service and also install the apk, but inside the service I don't have a Activity, I can to cast context to Activity obtained from getapplicationcontext(), but I catch the error that context can't be casted to com.android.Activity How I can to run

Android: how to run AsyncTask at regular interval in background service

我的未来我决定 提交于 2019-12-25 18:29:55
问题 How do I run an AsyncTask at regular interval of 2 mins sleep for 10 times in the background service? As VM stops my service at any time, my AsyncTask is also getting closed. I have tried ScheduledThreadPoolExecutor , Timer , TimerTask all gets stopped once Service gets stopped. Is there a good option start with? Any help is appreciated. 回答1: Your service will never get stopped but you should show notification. Try implementing foreground service. foreground service Foreground service

Keep activity alive in background until user doesn't kill or close app?

此生再无相见时 提交于 2019-12-25 16:55:06
问题 Can I keep Android activity alive in background, until user doesn't kill or close the application. I want to detect user clicks in background some specific hardware button clicks, as onKeyDown is not available in service, I need to keep my activity alive in background until user kills the app. Does android allows such behavior ? Update : I was able to solve this using following approach : 1] Use foreground service, Ref : https://developer.android.com/guide/components/services.html#Foreground

Android - Service does not start

心已入冬 提交于 2019-12-25 11:50:35
问题 I am making app for me and my class mates, that checks for new homeworks and exams. It has service that may not be killed beacuse of checking school server (like every 5 minutes) for changed size of file with list of exams and stuff like this. I tried following code: MayinActivity.java package com.test.simpleservice; import android.app.ActivityManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java

Receive SMS after closing App in Android

大憨熊 提交于 2019-12-25 09:27:52
问题 I need to read incoming SMS. I'm using BroadcastReceiver for this. It's working fine but when app is closed BroadcastReceiver also close. Here is code that I'm using. Manifest <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <uses-permission android:name="android.permission.READ_SMS"/> <!--other code --> <receiver android:name=".IncomingSms"> <intent-filter> <action android:name="android.provider.Telephony.SMS