android-service

How to read data and listen to changes from Room database in a Service?

徘徊边缘 提交于 2020-06-12 03:00:06
问题 i am storing user information in a local room database. In activities and fragments I use AndroidViewModel and LiveData to listen to changes made to the database and update the UI. Now I want to analyze all of the past user data to give recommendations for future decisions. My recommendations change on every change to the database made by the user so I need to update my reommendations frequently while doing the same calculations over and over again. I was thinking about starting a service on

How to check is app in foreground from service?

人走茶凉 提交于 2020-05-25 10:42:13
问题 I need to show notification to user only if application is not in foreground. Here is my public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { if(applicationInForeground()) { Map<String, String> data = remoteMessage.getData(); sendNotification(data.get("title"), data.get("detail")); } } need to implement applicationInForeground() method 回答1: You can control running app processes from android system

Send “share intent” (ACTION_SEND) from activity to service

限于喜欢 提交于 2020-04-30 08:51:20
问题 The task is to process somehow "share" intent in already running service . As far as ACTION_SEND is an activity action we have to pick up intent in activity and broadcast it to service. The problem is that it's logically to implement all "share intent" processing in service and use activity only for broadcasting intent. So the service have to receive the intent (which previously received and broadcasted by activity) so we can call getType() and get****Extra***() to it in order to know what

How to trigger a launch Activity intent when my app is closed on Android 10/Q?

时间秒杀一切 提交于 2020-04-18 03:47:32
问题 I am trying to create an app that will open another app at a specified time. To do this, I used an AlarmManager that starts a service. It works just fine if my app is open when the alarm is triggered. I get a notification that the service started, and the other app opens. However, if my app is in the background (after pressing the home button), and the alarm triggers, I get a notification that the service started, but the other app does not launch. What am I doing wrong? I am testing this on

How to apply changes to widget when placing it on the homescreen in onEnabled?

怎甘沉沦 提交于 2020-03-06 02:31:32
问题 When I try to put my weather widget on the homescreen I want to give the user an option of choosing a city at that moment and the widget starts showing the weather for that city. For this I have made use of onEnabled method in Provider class. So what I am doing here is just starting an activity to some preference class where I make use of string array to give the user the option to choose. And then OnSharedPreferenceChangeListener inside onEnabled again I am starting another activity with the

Intent BOOT_COMPLETED not working on Huawei device

烈酒焚心 提交于 2020-02-23 05:39:28
问题 I want to listen to APN Changes in my Android App. Therefore I start a Service on android.intent.action.BOOT_COMPLETED . This Service starts a ContentObserver which listens to changes to content://telephony/carriers/preferapn . I tested this setup on a few different devices (e.g. LG Spirit with Android 5.0, Samsung A3 with 6.0, Emulator Nexus5 with 7.0 and Huawei P9 Lite with 7.0) On the Huawei phone onCreate of my Service is not called. My other approach with android.intent.action.ANY_DATA

Are there any benefits to using Context.startForegroundService(Intent) instead of Context.startService(Intent) for foreground services?

天涯浪子 提交于 2020-02-20 06:44:27
问题 I read in the docs that Context.startForegroundService() has an implicit promise that the started service will call startForeground() . However, since Android O is coming out with changes to background and foreground services, are there any other performance improvements that it has compared to using the older startService() method, or is it just best practice going forward? 回答1: It's about neither performance improvements, nor benefits, nor best practice. Starting from API 26, system just

Action buttons in notification are showing but when pressed not working

倾然丶 夕夏残阳落幕 提交于 2020-02-06 08:12:46
问题 I am using a service to start the mediaplayer as soon as the notification is shown and then stop the service when the action button is pressed. The service starts fine. But the service doesn't stop on clicking the action button. This is my notification builder public NotificationCompat.Builder getReminderNotification(String title,String message,PendingIntent intent1){ return new NotificationCompat.Builder(getApplicationContext(),reminderChannelID) .setContentTitle(title) .setContentText

Action buttons in notification are showing but when pressed not working

China☆狼群 提交于 2020-02-06 08:12:02
问题 I am using a service to start the mediaplayer as soon as the notification is shown and then stop the service when the action button is pressed. The service starts fine. But the service doesn't stop on clicking the action button. This is my notification builder public NotificationCompat.Builder getReminderNotification(String title,String message,PendingIntent intent1){ return new NotificationCompat.Builder(getApplicationContext(),reminderChannelID) .setContentTitle(title) .setContentText

Hide installed app in android

Deadly 提交于 2020-02-03 00:37:26
问题 i want to hide the installed app by another app in android application, lets say user has installed 3rd party app called Skype, Watsapp, facebook etc... is there a way we can hide and show them upon click of a button from another app?. i tried below code. No luck, nothing happened to my launcher PackageManager packageManager = context.getPackageManager(); ComponentName componentName = new ComponentName(context, LauncherActivity.class); packageManager.setComponentEnabledSetting(componentName,