foreground-service

Guarantee that android keeps on retrieving sensor data

心不动则不痛 提交于 2019-12-14 02:51:50
问题 I'm developing an app that tracks trips. After searching about this matter, I concluded that the best way to achieve this (continuously track the user's location) is to use a foreground service. In some cases is working quite well, but in some other cases (even with DOZE off), I get some time intervals in which the phone is completely still and I stop getting sensor data (either accelerometer or locations from fused location provider). This problem got worse when I tried it in an Android 9

Make a notification from a foreground service cancelable once the service is not in foreground anymore

丶灬走出姿态 提交于 2019-12-13 15:14:23
问题 I have a music control notification that allows the user to start/stop the music. I want exactly the same behavior than the Google Play Music app notification: when music is playing, the service is in foreground and the notification not cancelable, and when the music is not playing the service is not in the foreground anymore and the notification can be removed. It works fine but when I cancel the foreground of my service, the notification is quickly removed before reappearing just after.

How to make notification dismissible when playing music in background like in Spotify and Google Music

风流意气都作罢 提交于 2019-12-12 18:35:16
问题 Spotify and Google Music allows a user to play music in background allowing also the media notification to be dismissible. When you move one of these apps to background, then pause the playback, you are able to dismiss the media notification. However if you don't dismiss the notification, so it is left in paused state for long time, the System won't kill the "audio service" as the notification is always visible and immediately react to play/pause. As far as I know it is not possible using

Why can't we call StopForeground() method in the broadcast receiver class?

ぐ巨炮叔叔 提交于 2019-12-12 02:09:21
问题 I have a broadcast receiver class and when I receive a particular broadcast I would like to stop the foreground notification. So I tried context.stopForeground() but the intellisense did not show the method. How can we call the stopForeground() method in the broadcast receiver class ? public class Broad extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction()==Const.ACTION_STOP) { // unable to call like this context.stopForeground();

Context.startForegroundService did not then call Service.startForeground: Alternative solution

烂漫一生 提交于 2019-12-11 03:24:10
问题 Note: This question assumes you know binding a service to a context. Everyone on the production is aware of this issue, or even some users that have an Android Oreo or Pie device. The exception looks like this: Fatal Exception: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop

Foreground Service dont run constantly

匆匆过客 提交于 2019-12-11 00:40:00
问题 In my app I use a foreground service that must run constantly. Sometimes the foreground service is stopped. Under what circumstances can the OS kill my service (it happen even if there is enough memory, battery is full, phone is charging)? This is what my code looks like until now: public class ServiceTest extends Service { public static Thread serverThread = null; public Context context = this; public ServiceTest(Context context) { super(); this.context = context; } public ServiceTest() { }

Forgeround service stop after a few minutes or locking the phone

核能气质少年 提交于 2019-12-10 18:05:48
问题 I try to create foreground service that toast a message every 20 second but this service stop after a few minutes or locking the phone. I test this service in android 8 (O). my code is : @Override public int onStartCommand(Intent intent, int flags, int startId) { input = intent.getStringExtra("inputExtra"); new Thread(new Runnable() { public void run() { while (progressStatus < 10000000) { progressStatus += 1; handler.post(new Runnable() { @SuppressLint("MissingPermission") public void run()

Foreground Service being killed on Notification click

时间秒杀一切 提交于 2019-12-10 14:32:57
问题 In Android 4.4.2 clicking on my Foreground Service notification is killing my process. On older devices (Samsuing Tab 2 running 4.2.2), I can swipe away the Activity from Recent Tasks and still have my Service running fine in the background. Then when I click on the Notification my app Activity starts again quite happily. However, once I click the Notification on my Nexus 7 running 4.4.2 my process is killed (which up until the click is running happily in the background). The PendingIntent

Foreground notification service not working in one plus devices

余生颓废 提交于 2019-12-10 11:29:46
问题 Below is the code for starting the foreground service. It is working fine for many devices like Samsung, moto, Vivo, Oppo and also with Android version nougat and oreo, but not working on One plus devices. Can anyone let me know if any extra changes or permission is required to run in One plus device or if any emulator supports one plus phones. public class ForegroundService extends Service { private Context ctx; private static final String PRIMARY_NOTIF_CHANNEL = "default"; @Override public

startForegroundService() did not call startForeground(), but it did

柔情痞子 提交于 2019-12-09 10:06:52
问题 I'm having the Context.startForegroundService() did not then call Service.startForeground() in my Android service, but I cannot figure out why it is happening. My application is for media streaming, and this error only occurs when you pause from the foreground notification (turning it into a regular notification), and you then swipe the notification away, which is intended to stop my service. Here is the only method where the startForegroundService , startForeground and stopForeground methods