android-service

java.lang.ClassCastException while running new `runnableThread` in `Service` Class

China☆狼群 提交于 2019-12-06 10:53:06
问题 I have an application , contains a broadcastReceiver which listens to all new received SMS . If any new SMS received this BroadcastReceiver starts a background Service which runs GPS and return the coordinates , this coordinate retrieving needs a new thread to be run , in the Service class there is no getApplicationContext() so I used 'getContentBase()' for starting the new thread this is the code ((Activity)getBaseContext()).runOnUiThread(new Runnable() { ((Activity)getBaseContext())

Is it possible to use AWS Android TransferUtility in Service?

半世苍凉 提交于 2019-12-06 10:45:53
The AWS Android SDK for S3 includes classes for data transfers. Namely, the TransferUtility . The TransferUtility seems to create a service for its own use. Is it possible to use it from a service and in particular set the transfer listener and use it to send updates to application or create notifications from within said service? Yes it's possible to start a service from another service. TransferUtility may fail to work if its Amazon S3 client gets garbage collected before TransferService gets it. Normally an object is passed as a parcelable in an intent between components. However it's quite

foreground service without notification

佐手、 提交于 2019-12-06 10:41:17
问题 I want to start a foreground service that doesn't show notification, apps like instagram, telegram, zapya, ... have a foreground service and they show no notifications. I have tested ways like answers here, but android shows a notification that yourAppName is running . I want to know how is that possible to have a foreground service with no notification or warning from OS? 回答1: How to do it Here's an up-to-date technique to make it work on all Android versions: When the app is running on an

Pending Intent created in Native Extension works only from Notification but not within Service

点点圈 提交于 2019-12-06 10:38:06
I’m developing an Air mobile application for Android which uses Air Native Extensions (ANE). From the ANE I call a function that creates a Pending Intent which is passed to a Notification. Next, the native function starts a service and passes it the Pending Intent and the Notification. Here’s the code for that part: public class StartServiceFunction implements FREFunction { @Override public FREObject call(FREContext context, FREObject[] args) { Log.d("MyApplicationStartServiceFunction", "call(StartService)"); Context applicationContext = context.getActivity().getApplicationContext(); try {

Android - Create a background service to receive PubNub messages

青春壹個敷衍的年華 提交于 2019-12-06 08:53:38
I am using PubNub API to get real time messages. I have implemented code to subscribe to my channel and receive ongoing messages. I just want these messages to receive in background even if my application is not open. I have learned about services and broadcast receiver in android but I am not understanding the how to use this with PubNub. Is there any proper way to achieve this? PubNub Subscribe Code public static final String GLOBAL_CHANNEL = "NAME_OF_MY_CHANNEL"; public void subscribe() { Callback callback = new Callback() { @Override public void connectCallback(String channel, Object

Android: AlarmManager used to call a Service to notify the user

≡放荡痞女 提交于 2019-12-06 08:36:28
Edit Adding this line in my manifest solved my problem (the Service is well created). <service android:name=".TimersService" > Post I'm currently trying to implement alarms to notify the user that a countdown has finished. I have a method createAlarm() that adds a new Alarm through an AlarmManager . This method is currently called inside a Fragment. It looks like this: private final void createAlarm(String name, long milliInFuture) { Intent myIntent = new Intent(getActivity().getApplication(), TimersService.class); AlarmManager alarmManager = (AlarmManager) getActivity() .getSystemService

Service and IntentService, Which is better to run a service that poll database value from the server?

一笑奈何 提交于 2019-12-06 08:31:18
I had read quite a number of resources regarding the Service and IntentService . However when come to make a decision, I am not confident enough to choose which type to use in order to create a background service that will poll data from database in a time interval and stop it when I get the data I want since the data represent a status of a request, eg. ordering medicine confirmation status(pending, completed, in progress). I need to detect when a status is set to "completed" and send a notification to alert the user that the order is completed. After that the service will stop itself

IBinder casting *sometimes* results in ClassCastException when binding to service

只愿长相守 提交于 2019-12-06 08:20:59
We bind to our local service (same process) in Application subclass but sometimes we are getting a ClassCastException. I have no idea how to fix it since everyone says the exception occurs if the service process is different than your application. How can this be fixed? Application subclass: public class App extends Application implements ServiceConnection { private ServiceApi exposedServiceApi; private EventBus eventBus; @Override public void onCreate() { super.onCreate(); bindToService(); } public void bindToService() { if (isConnectedToService()) { return; } boolean successfulBindCall =

Android: get reference to started Service in instrumentation test

我的未来我决定 提交于 2019-12-06 08:20:21
问题 I'm trying to write instrumentation test for my NetworkMonitorService as described in the official "testing your service" documentation. Currently I'm stuck because I can't figure out how can I grab a reference to the started service in order to inject mocks into it and assert behavior. My code: @RunWith(AndroidJUnit4.class) @SmallTest public class NetworkMonitorServiceTest { @Rule public final ServiceTestRule mServiceTestRule = new ServiceTestRule(); @Test public void serviceStarted

android service START_STICKY START_NOT_STICKY

╄→гoц情女王★ 提交于 2019-12-06 06:22:15
问题 I need to keep my service always running in background. And starting my service with "startService()" function. I don't want to restart service whatever is Application's state. Here is my observations. START_STICKY > if application starts , service is restarting. And service is restarting itself when application closes , too. START_NOT_STICK > service doesn't work after application closed. I need a service which always running , and it will receive broadcast when application starts. Services