android-service

How Can I count the number of screen unlocks by a user in Android?

守給你的承諾、 提交于 2019-12-25 09:02:28
问题 I am currently working on an Android App which informs the number of screen unlocks he/she has done over a day. This example can be seen on stock android devices with API Level P or higher in the feature named Digital Wellbeing. I would like to know how does it work. 回答1: You can add reciever like this in your Activity : private LockScreenStateReceiver mLockScreenStateReceiver; int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

Android: AlarmManager is not getting fired

那年仲夏 提交于 2019-12-25 08:56:48
问题 I am trying to generate an alarm on a scheduled time in future. Below is the code MainActivity.java import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android

android sound gets disabled after sometime

自闭症网瘾萝莉.ら 提交于 2019-12-25 08:49:19
问题 i want to check how the service feature set in android works. to check it, i have a controller class that will start the service. in the service i have a handler that executes a function every minute.the function plays the sound. everything works well when the screen is on but after the screen goes dark(off), the sound is heard about 2-3 times (2-3 minutes) and then it stops... any idea why? and how can i make it (execute the sound function)work every minute? 回答1: When the phone goes into

Create a Android App Service which run even after app is terminated

…衆ロ難τιáo~ 提交于 2019-12-25 08:34:47
问题 This is service which I wanted to run in the background public class CustomMyService extends Service { public CustomMyService() { } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } @Override public IBinder onBind(Intent intent) { return null; } @Override public void onTaskRemoved(Intent rootIntent) { Intent intent = new Intent("com.android.ServiceStopped"); sendBroadcast(intent); } } Manifest File <service android:name=".CustomMyService">

Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent?

六月ゝ 毕业季﹏ 提交于 2019-12-25 08:23:37
问题 Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent? consider in activity: Intent intent; intent = new Intent(MyIntents.ADD_BATCH_ACTION); intent.putExtra(MyIntents.BATCH_ACTION_NAME, "Bake donuts"); startService(intent); intent = new Intent(MyIntents.ADD_BATCH_ACTION); intent.putExtra(MyIntents.BATCH_ACTION_NAME, "Make a coffee"); startService(intent); intent = new Intent(MyIntents.ADD_BATCH_ACTION); intent.putExtra(MyIntents.BATCH_ACTION

Sending broadcast to restart service to keep-alive not working correctly

时光毁灭记忆、已成空白 提交于 2019-12-25 08:21:35
问题 I have an Android service that in onDestroy() method I'm sending a broadcast to restart my service. It's work on sony and samsung rom! but not work in Xiaomi or Huawei rom. How do I handle this? This is my code. Manifest: <receiver android:name=".Receiver.AppStartReceiver" android:enabled="true"> <intent-filter> <action android:name="example.app.start" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> Service: public class NotificationsService

Android Widget+Service

谁说胖子不能爱 提交于 2019-12-25 08:13:55
问题 I have a music player which plays music using a service,all the broadcast receivers within that service are defined inside the service and not externally. I am totally new to widgets so i had been seeing a few tutorials.But they didn't help me much I am totally new to pending intents soo.I am so confused right now please help me out... All i want to do is just trigger the broadcast inside the service using the button of the widget ... Here is the copy pasted code which i had been trying to

Android service START_STICKY not working in micromax q382 phone (android 5.1 lollipop) and working for Kitkat/marshmallow

大城市里の小女人 提交于 2019-12-25 07:50:01
问题 Android service START_STICKY not working in micromax q382 phone (android 5.1 lollipop) and working for Kitkat/marshmallow i.e working in lower version and higher version but not in specific to micromax q382 phone (android 5.1 lollipop). Below is code for my service import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.support.v4.app

android notification works for one object in a loop [duplicate]

喜你入骨 提交于 2019-12-25 07:39:35
问题 This question already has answers here : How to create Multiple statusbar Notifications in android (5 answers) Closed 5 years ago . I have an android service which connects to a server using web service, the service return many json objects, I want to run notification for each object, I did all of that but I have problem which is i just see one notification even thought the server is sending two objects. please look at the for loop,it is obvious that i am calling many notifications, why I

The best way to deliver result from Service binding in Android

≯℡__Kan透↙ 提交于 2019-12-25 07:36:59
问题 How to get result from the Service, if task run asynchronously? If a task is started synchronously in main thread, there is no problem: Object result = serviceInstanceInActivity.callMethod(); But if the task runs in other thread, we have a problem: void asyncMethodInService() { new MyTask().execute(); } class MyTask extends AsyncTask<Void, Void, Result> { // implementation of the others methods public void onPostExecute(Result result) { // We need to send data to Activity here } } Of Course,