android-service

Check if service is running on Android?

落爺英雄遲暮 提交于 2019-11-28 06:32:31
l want to check if a service is running l wrote this code public class startServiceOrNo { public static void startServiceIfItsNotRuning(Class<?> class1, Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (class1.getName().equals(service.service.getClassName())) { Lg.d("servisstart SERVICE ALREADY START" + class1.getName()); return; } } Lg.d("servisstart SSERVICE NEW SERVIS " + class1.getName()); context.startService(new Intent(context, class1));

How to auto restart a service when killed?

最后都变了- 提交于 2019-11-28 06:12:49
问题 I have already red many posts about the subject, some of these works, but only on some devices. For example it works on my Nexus 4, Nexus 5 with cyaogenmod, but not on my Xiaomi Mi2s (jelly beam 4.1.1) I tried setting it sticky, using alarm, and broadcast receiver on destroy. But neither of them worked out. When I kill the application it never wake up again. But on the same device Whatsapp works perfectly, and even if I kill it, it wake up again.. Is there any way to do it without use GCM?

How to add a floating view to Android Window manager and listen to System/Hardware back button events

那年仲夏 提交于 2019-11-28 06:02:31
I have a service which displays a floating view on the window manager (using WINDOW_TYPE_ALERT permission). I'm able to display it and perform actions. But, I have two specific questions: Regarding the implementation of the floating view How to listen to system back button event so that I can dismiss the view. Implementation: In the manifest I added permissions for: <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> I have a broadcast receiver which will listen for Alarm events. Upon receiving the event, I'm starting a service to display the floating view. The following

USSD service not working

烈酒焚心 提交于 2019-11-28 05:58:10
I'm trying to develop an application which silently dismiss the USSD responses. I've used the code from http://commandus.com/blog/?p=58 with minor changes. I've created the IExtendedNetworkService.aidl in the package com.android.internal.telephony and USSDDumbExtendedNetworkService inside the package com.commandus.ussd . The problem is, nothing happens after running the application (even after restarting the phone). Can someone point out what am I doing wrong? Should I write any additional code for making it work? IExtendedNetworkService.aidl package com.android.internal.telephony; /** *

Broadcast Intent on contact added/edited/changed - android

删除回忆录丶 提交于 2019-11-28 05:34:14
问题 In my app, I have a service in which I want to listen for any changes in contacts i.e., when any contact is added or edited in the native contacts app or through any other app. Is there any broadcast intent which I can register to for this purpose? Or is there any other way to achieve this? 回答1: Found someone with a similar problem, his solution was using RawContacts. Broadcast on contact add/change? http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html 来源:

How to call a method in activity from a service

China☆狼群 提交于 2019-11-28 05:20:28
There is a service that listens for some voice. If voice matches a string a certain method is invoked in the service object. public class SpeechActivationService extends Service { public static Intent makeStartServiceIntent(Context pContext){ return new Intent(pContext, SpeechActivationService.class); } //... public void onMatch(){ Log.d(TAG, "voice matches word"); } //... } This is how I start the service in my activity: Intent i = SpeechActivationService.makeStartServiceIntent(this); startService(i); From this service method, how can I invoke a method that resides in the activity object? I

Firebase push notification issue in Android when app is closed/killed

二次信任 提交于 2019-11-28 05:12:40
问题 Firebase push does not work on some devices when app is closed with only data payload. See this thread: https://github.com/firebase/quickstart-android/issues/41 I know when app is killed by swipe then some OEM kill all the services of the app which directly effect FirebbaseMessagingService and due to this onMessageReceived() method never invoked. I have also tried with high priority FCM but sadly no success. Here are the phones on which I am facing an issue: OnePlus, Lenovo, Huawei. Currently

Can you use a LoaderManager from a Service?

拥有回忆 提交于 2019-11-28 04:52:27
I have a data loading system set up using a custom Loader and Cursor that is working great from Activities and Fragments but there is no LoaderManager (that I can find) in Service. Does anyone know why LoaderManager was excluded from Service? If not is there a way around this? Does anyone know why LoaderManager was excluded from Service? As stated in the other answer, LoaderManager was explicitly designed to manage Loaders through the lifecycles of Acivities and Fragments . Since Services do not have these configuration changes to deal with, using a LoaderManager isn't necessary. If not is

WakefulIntentService implementation clarifications

前提是你 提交于 2019-11-28 04:32:47
问题 Commonsware's WakefulIntentService works beautifully but there are some things I do not quite get. Below is the core of the service - a stripped down version of the source : class WIS extends IntentService { private static final String NAME = WIS.class.getName() + ".Lock"; private static volatile WakeLock lockStatic = null; synchronized private static PowerManager.WakeLock getLock(Context context) { if (lockStatic == null) { PowerManager mgr = (PowerManager) context .getSystemService(Context

Does FirebaseMessagingService run in the background by default?

懵懂的女人 提交于 2019-11-28 04:07:47
问题 Does the FirebaseMessagingService run in the background similar to how an IntentService operates? I see that FirebaseMessagingService extents Service which does not run in the background, but I'd like to be sure whether or not I should be doing any work inside the FirebaseMessagingService asynchronously or synchronously. Thank you 回答1: FirebaseMessagingService 's method onMessageReceived(RemoteMessage message) is called "in the background" (not on the UI/Main thread). If you try do