android-service

Android HCE service

守給你的承諾、 提交于 2019-12-13 02:27:59
问题 I have a HCE service which sends data to and from a NFC reader but I was wondering if I can specify the launch settings of my service. I want to specify that my service can only be called if the app is running. If the app is closed the service shouldn't be called. Is this possible or was it intended that the service can always be called? 回答1: Currently you can only specify if the HCE service should be considered for card emulation from the lock-screen or only if the user passed the lock

Why my BroadcastReceiver stop receiving after a while

荒凉一梦 提交于 2019-12-13 02:24:07
问题 I have a IntentService that does a long work, it takes about 15 minutes to be done. It is a synchronization process to get new data from my server. When this service starts, I start a activity too, to display the progess. This activity creates a BroadcastReceiver , that intercepts messages sent from the service about the process progress. If I leave the app doing it job, after a while the SO switch off the screen. When I switch on the screen again, after about 15 minutes, the service has been

Android communication between applications using ResultReceiver

拟墨画扇 提交于 2019-12-13 01:56:59
问题 I have two applications. First application is simple service application which do some work in background and finish. I decided to use IntentService . @Override protected void onHandleIntent(Intent intent) { if (intent == null) { return; } ResultReceiver callbacks = intent.getExtras().getParcelable(EXTRA_CALLBACKS); ... The second application must consume the IntentService from the first using Intent in my case. public class SendActivity extends AppCompatActivity { private ResultReceiver

starting a service and returning data

和自甴很熟 提交于 2019-12-13 01:43:48
问题 today I was learning about Intents and binding an activity to service, I found it quite easy and great way to transfer data from the service to the activity. I wanted to test out an activity that would start a service, this service would call on a webpage to get some data. I binded the activity to the service so that the activity could call on the service method and then toast the results. In the service method I call on a webpage and return the data. When I tested it I was getting a null

starting a service from dialog box in android

放肆的年华 提交于 2019-12-12 23:38:14
问题 I'm trying to start a background service from a pop-up dialog and it's just doesn't work for me this is the code for opening the dialog box: reportWrongLang.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getFragmentManager(); ReportWrongLangDialog Dialog = new ReportWrongLangDialog(imageInfo.getParam("imageId")[0], getApplicationContext()); Dialog.show(fm, "are_you_sure_dialog"); } in the ReportWrongLangDialog i am saving the appContext

Pass Service From one Activity to Another

微笑、不失礼 提交于 2019-12-12 22:21:22
问题 how do I pass a service from one activity to another? I have a music player (Activity1) that displays a list of songs, and when you click on it, it starts the service within Activity1. I have a button that users can click that will open Activity2. So what is the best way for me to pass the service from Activity1 to Activity2. If the service is started in Activity1, then Activity2 should continue playing. If the service is not started in Activity1, then Activity2 should start the service

Timer inside Android service

微笑、不失礼 提交于 2019-12-12 20:23:54
问题 I have an Android service that starts a timer that does stuff: @Override public int onStartCommand(Intent intent, int flags, int startId) { timer.scheduleAtFixedRate(new VeryImportantTask(), 0, RATE); return START_STICKY; } I know Services are singleton but, does onStartCommand method called each time that I call startService() ? If so, I should control that my timer is just started the first time, shouldn't I? I'm thinking in a static boolean flag in the service. Is there a better way? 回答1:

onStartCommand is calling only once in service android?

这一生的挚爱 提交于 2019-12-12 20:04:04
问题 i have a simple service need to run in background.below is the code for the service.i want to run the code in onStartCommand repeatedly simply for test purpose i displayed toast.but Toast also calling only once import android.app.IntentService; import android.app.Service; import android.content.Context; import android.content.Intent; import android.net.wifi.WifiManager; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.support.annotation.Nullable;

Checking App is running?

陌路散爱 提交于 2019-12-12 19:53:05
问题 Is it possible for a service to check the following Whether a App is running or not? If yes, is it App running is background or foreground? Please suggest some way to do it. 回答1: You need to use getRunningTasks to know whether the app is running or not. From the docs: public List getRunningTasks (int maxNum) Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. For this to work you should include this in your AndroidManifest.xml

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