android-service

Background service to control proximity sensor

拥有回忆 提交于 2019-12-03 22:40:59
问题 I need to run a service (always in background, I want the service constantly checking even if the application is closed) that control the proximity sensor status, and when it's covered launch an activity. I tried but I had error. Any examples of something like this? P.S. In my AndroidManifest I added: <service android:name="xxx.xxxxx.xxxxx.MyService" android:enabled="true" /> Here my MyService.java: (Eclipse don't report any error but when I try it on my device, apps give a force close.)

Android widget update via service, that is doing http requests

只谈情不闲聊 提交于 2019-12-03 22:07:05
what is the best strategy for the following scenario: my app will periodically send and receive http requests to a server run PHP script. I tried a service fired by AlarmManager or clicking directly on its widget. Direct operations on the device are working fine (like random numbers, see http://www.vogella.com/tutorials/AndroidWidgets/article.html ) when it comes to the request, these should be done in async tasks. I tried to update the widget (remoteView) from the postexecute section of the async task, but it is not working. Somebody could give me some hints or maybe snippets? thank you in

MediaBrowserServiceCompat vs mediaSessionCompat?

霸气de小男生 提交于 2019-12-03 21:59:59
I just developed a music app (local songs) When trying to build playback control on lock-screen and notification using mediaSessionCompat I found ianhanniballake's following link: https://medium.com/google-developers/mediabrowserservicecompat-and-the-modern-media-playback-app-7959a5196d90#.kfvx5jfyn Though the blog was nicely explained, I didn't understand the difference between mediaSessionCompat and MediaBrowserServiceCompat. Can someone explain why MediaBrowserServiceCompat is used? Is it necessary? Is mediaSessionCompat enough? Thanks in advance mediaBrowserCompat and

Service is not stop in android. how to fixed issues

别来无恙 提交于 2019-12-03 21:59:31
I start service from an android activity startservice(intent); stopservice(intent); When i call for stopping service but service it does not stop actually my service class contains LocationListener that get latitude and longitude and then store in sqlite and also sent such information into server. Another issue is LocationUpdate method is automatically call after second How to extend time e.g 30 second How to stop service to stop LocationListener and storing value in sqlite server. UpdateServices.java public class UpdateServices extends Service implements LocationListener { String id, latee,

BroadcastReceiver within a Service not receiving broadcasts Android

北城余情 提交于 2019-12-03 18:10:22
问题 I've got this app, in which users update certain variables in an Activity, and this Activity passes the new variables to a IntentService using a BroadcastReceiver. However, the BroadcastReceiver in the IntentService doesn't seem to be receiving the broadcasts. This is the code within the service to create the broadcast receiver protected class UpdateReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent){ Log.d("receiver", "Got message: "); //state

get Activity's reference from a Service

情到浓时终转凉″ 提交于 2019-12-03 17:37:11
问题 I need to get a reference to the main Activity from a Service. This is my design: MainActivity.java public class MainActivity extends Activity{ private Intent myIntent; onCreate(){ myIntent=new Intent(MainActivity.this, MyService.class); btnStart.setOnClickListener(new OnClickListener(){ public void onClick(View V){ startService(myIntent); }); }} MyService.java class MyService extends Service{ public IBinder onBind(Intent intent) { return null; } onCreate(){ //Here I need to have a

Android get current song playing and song changed events, like Musixmatch

耗尽温柔 提交于 2019-12-03 17:33:32
What i want to achieve is very similar to what Musixmatch is doing. I need to be informed when the music starts playing and when the song is changed. All this in the service because my app may be closed (even musicmatch does this). In the above case even if Musixmatch app is not running i get a notification when ever i change the song on spotify or any player. Can anyone pls tell me how to achieve this. I don't need the code help, just what to know how to achieve it. I'm really confused how Musixmatch is doing it. Here is a solution to find if music player is playing. AudioManager manager =

Service not being created (or connecting) after bindService()

你离开我真会死。 提交于 2019-12-03 17:25:13
问题 I have this simple service that broadcasts the current location of the user. I want to use the binding mechanism just to control the service life-cycle, but the service is just not starting. What did I do wrong? public class GPSActivity extends ListActivity { ... protected void onResume() { super.onResume(); Log.i("Service", "Service bound"); Intent intent = new Intent(this, LocationService.class); bindService(intent, service_connection , Context.BIND_AUTO_CREATE); } protected void onPause()

Clarification of setUpdateCurrent on OneOffTask

一世执手 提交于 2019-12-03 16:39:15
I'm trying to wrap my head around the behaviour of setTag and setUpdateCurrent of OneoffTask in the GcmNetworkManager tooling. The documentation of setUpdateCurrent says this: Optional setter to specify whether this task should override any preexisting tasks with the same tag. This defaults to false, which means that a new task will not override an existing one. Fair enough, but it doesn't say what will happen to a task, it only says one thing that will not happen - i.e. the task will not overridden. :) It's not clear to me if using setUpdateCurrent means that duplicate tasks are allowed of it

Android media player seekbar

核能气质少年 提交于 2019-12-03 16:15:45
I have a service that creates, plays and handles a mediaplayer (just audio), yet I have a seekbar in the main activity that I want to, naturally, show the progress of the audio file and allow the user to seek to various positions. What I'm having a hell of a time figuring out is: what would be the best or proper way to connect the seekbar in the UI to the mediaplayer in the service? inazaruk Here is how I would do this: Bind to service that plays audio. The interface that server returns in onBind should have getCurrentPos() and getDuration() functions. In your Activity's onCreate bind to