android-service

Foreground service getting killed from Oreo

☆樱花仙子☆ 提交于 2019-11-29 22:41:14
I have written a foreground service which is working properly for all OS version lower than Oreo. From Oreo application process is getting killed after 5 minutes of closing and removing the application from recents. As per android developer documentation for background execution limitations OS should not kill application for which a foreground service is running and notification is shown in notification window. As per guidelines on developer documentation. I followed below steps to start foreground-service. Foreground service is started with startForegroundService() method Within 5 sec after

Using an Android Service to handle a network connection

拈花ヽ惹草 提交于 2019-11-29 22:30:40
问题 I'm working on an Android app that needs to maintain a network connection to a chat server. I understand that I can create a service to initiate the connection to the server, but how would the service notify an Android Activity of new incoming messages? The Activity would need to update the view to show the new messages. I'm pretty new to Android, so any help is appreciated. Thanks! 回答1: Can you pass a handler to your service? First, define your handler as an interface. This is an example, so

Transfer InputStream to another Service (across process boundaries) with ParcelFileDescriptor.createPipe() failes with “EBADF (Bad file number)”

吃可爱长大的小学妹 提交于 2019-11-29 21:57:14
I want to "send" an InputStream from one Android Service to another service running within a different process by using ParcelFileDescriptor.createPipe() , a stream-to-stream copy thread and a ParcelFileDescriptor, representing the read side of the pipe, which is given to the other service with means of Binder IPC. Sending Code (Process A) I want to send a given InputStream to the receiving service: public sendInputStream() { InputStream is = ...; // that's the stream for process/service B ParcelFileDescriptor pdf = ParcelFileDescriptorUtil.pipeFrom(is); inputStreamService.inputStream(pdf); }

Minimal android foreground service killed on high-end phone

孤者浪人 提交于 2019-11-29 20:42:43
I'm trying to create an app that lets users log routes (locations/GPS). To ensure locations are logged even when the screen is off, I have created a foreground service for the location logging. I store the locations in a Room Database which is injected into my service using Dagger2 . However, this service is killed by Android which is, of course, not good. I could subscribe to low memory warnings but that doesn't solve the underlying problem of my service getting killed after ~30 minutes on a modern high-end phone running Android 8.0 I have created a minimal project with only a "Hello world"

Is there a straightforward way to stop a service in response to a user clicking a notification?

心不动则不痛 提交于 2019-11-29 17:49:20
问题 I'd like the following behavior: The user clicks a notification and Android stops my Service. The problem is that stopping a Service requires a call to stopService and I cannot easily create a PendingIntent that does that. So the only way I found to do this is to have my Service receive a special Intent extra that causes the Service to call stopSelf and stop. Is there a simpler way to directly cancel a Service from a notification click? 回答1: You could create a simple BroadcastReceiver that

Binding to a service from another app

痴心易碎 提交于 2019-11-29 17:05:23
问题 I wrote two apps (target Gingerbread). Let say app1 and app2. App1 has two services started with "BOOT_COMPLETED" and they are started with the return value START_STICKY. They run in separate threads. To make a long story short. One of the service is watching for incoming data on a serial port (a kind of proxy for app communicating with interfaces on the other end of the serial port). The other has a listener watching some system status and waiting for some "instructions" from other apps. I

When does ServiceConnection.onServiceDisconnected() get called?

自古美人都是妖i 提交于 2019-11-29 16:07:55
问题 I'm messing with Android services, and I have found that ServiceConnection.onServiceConnected() gets called fairly predictably when I bind to a service. However, my onServiceDisconnected() method seems to never be called, even after the VM dies. I have logged debug messages on the service and show that all threads have been shutdown, etc. I know services are implemented as processes; are there threads I don't know about that are preventing the process from exiting? 回答1: It happens upon remote

Android: take a 'screenshot' of a web page from a background service?

不打扰是莪最后的温柔 提交于 2019-11-29 15:34:14
问题 I have a URL for a web page, and I want to take a 'screenshot' of this web page in the background, eg. in a Service, and without showing a UI to the user. I have tried to create a WebView in my Service, and then use the capturePicture() method to get the screenshot when the page has finished loading, but the created Picture (and the Bitmap I create from it ) is always empty. (This works perfectly in a normal Activity, but not in my background Service). Any way to get this to work, or an

Cant cancel Notification using NotificationListenerService

 ̄綄美尐妖づ 提交于 2019-11-29 15:21:39
This is my service: public class Listener extends NotificationListenerService { Context context; @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); } @Override public void onNotificationPosted(StatusBarNotification sbn) { String pack = sbn.getPackageName(); String ticker = sbn.getNotification().tickerText.toString(); Bundle extras = sbn.getNotification().extras; String title = extras.getString("android.title"); String text = extras.getCharSequence("android.text").toString(); Log.i("Msg",pack); Log.i("Msg",ticker); Log.i("Msg",title); Log.i("Msg",text);

part-2 persistent foreGround android service that starts by UI, works at sleep mode too, also starts at phone restart

白昼怎懂夜的黑 提交于 2019-11-29 15:15:01
问题 Status: Really thankful to all who helped and guided here and in part-1! I have made code out of research and help given and have put that working code in EDIT-1 . Criticisms are welcomed to make the code better. Scenario: I asked the question mention in Part-1, but for some reason I can persistently cannot make a design and correct strategy with code that has true integration and sanity. It was a lengthy question and the question nor answer could have been concluded or finalized in just one