Set notification at specific time via Google Workmanager [duplicate] - java

This question already has answers here:
How to schedule notifications using WorkManager?
(5 answers)
Closed 4 years ago.
I already used Android Job library for schedule job but Once Google announced Workmanager library in I/O 2018 . I want to use it as alternative but unfortunately I couldn't use it to schedule notification at specific time like - for example - event notification at 8:30 am
This is my workmanager request code
Data data = new Data.Builder()
.putString("EVENT_ID", event.id)
.putString("EVENT_TITLE", event.eventTitle)
.putString("START_TIME", event.startTime)
.build();
long delayToPass = getTriggerTime(triggerTime);
OneTimeWorkRequest compressionWork = new OneTimeWorkRequest.Builder(EventWorker.class)
.setInputData(data)
.setPeriodStartTime(delayToPass, TimeUnit.MILLISECONDS )
.build();
WorkManager.getInstance().enqueue(compressionWork);
my code read trigger time from database .. I want to run notification at trigger time in database when Event occur via Workmanager library

WorkManager is not designed for that scenario. You would have to use AlarmManager.

Thanks, but I already use Evernote Android Job library to achive this scenario . but I read this next quote in their github readme
WorkManager is a new architecture component from Google and tries to solve a very similar problem this library tries to solve: implementing background jobs only once for all Android versions. The API is very similar to this library, but provides more features like chaining work items and it runs its own executor.
If you start a new project, you should be using WorkManager instead of this library. You should also start migrating your code from this library to WorkManager. At some point in the future this library will be deprecated.
Starting with version 1.3.0 this library will use the WorkManager internally for scheduling jobs. That should ease the transition to the new architecture component
I want to know what it means?

Related

Best Android Scheduler to Update UI

I am new to Android and working on this chat app where I want to change an Activity element based on a predetermined data on predetermined exact times. It doesn't have to work when app or phone is closed but I want to send notifications as well with the change. There is AlarmManager, JobScheduler, Handler, Timer, WorkManager but I am extremely confused about how they compare to each other. Which is the best option in this case?
In fact, WorkManager under the hood uses all of these scheduling APIs depending on the API level. This means that you won't have to deal with finding the best API for devices, because WorkManager will pick up the appropriate API for you.
You can also read the official documentation for more info and comparison: https://developer.android.com/topic/libraries/architecture/workmanager
The WorkManager API is a suitable and recommended replacement for all
previous Android background scheduling APIs, including
FirebaseJobDispatcher, GcmNetworkManager, and Job Scheduler.

Repeating operation in Android without alarm manager

I created application for sending sms interval. I used AlarmManager, which worked good, however after few days of proper working (send SMS at established time). It starts sending at different time or desist.
As far as I know, this is often problem with AlarmManager.
Is there some trap with AM ? or maybe you know better solution, library for that type of problem?
Thanks in advance
if the interval of time for sending the email is more than 15 minutes, I suggest you to use JobScheduler. That work really good over all android versions. I mentioned more than 15 mins because JobScheduler only can schedule at least every 15 mins on android 7 and over.
JobScheduler is an option, but this is only available on Android API Level 21+ (Lollipop v5.0).
A better option is to use WorkManager, currently in beta, that provides the same functionality (and limits like the mentioned 15 minutes minimum interval) but down to API level 14.
You can find more information about WorkManager on this series of blogs and on the documentation.

How to schedule notification for a specific date and time in android studio? [duplicate]

This question already has an answer here:
Set notification for specific date and time [closed]
(1 answer)
Closed 4 years ago.
I want to set notification for a specific date and time (ex: 15/7/2018 02:00:00) in Android.
Can anyone help me?
Thank you.
Actually, it's not a duplicated question since the Android background and scheduling management changed dramatically on the newer versions; it's not really good practice to use AlarmManager.
also, you are not able in most cases.
I recommend using WorkManager from the recent jet pack project.
take a look at
Schedule tasks with WorkManager
WorkManager might use JobScheduler, Firebase JobDispatcher, or AlarmManager. You don't need to write device logic to figure out what capabilities the device has and choose an appropriate API; instead, you can just hand your task off to WorkManager and let it choose the best option.

Android - What is the best practice for background tasks?

my app lets user create scheduled task.
Example: Tomorow show this notification => this notification leads to this activity etc.
What is the best practice to do this? Do I need to use some background task manager? How can I do this so it will work even when App is not running?
Facebook is doing something similar, when it is not running it still checks web for useful info for you.
Can somebody point me to some tutorial or get me some example? Thank you
There are several solutions that are recommended by Android framework team
Firebase JobDispatcher
GCM Network Manager, codelab
Job Scheduler api 21+
For showing a notification at a known point in the future (either a specific time or X hours from now) use AlarmManager to set an alarm.
For getting notifications from a server, generally you'd use push messages from the server. Although polling the server on an alarm would also work.

Java android track usage time installed app

I need to track usage time of all installed apps, with java, in android OS.
For example, this app is very very similar: https://play.google.com/store/apps/details?id=com.agrvaibhav.AppUsageTracking
Is there a way to do this?
First of all you can use the android.app.ActivityManager to retrieve phone statue and running processes. An excellent example of doing this could be found here,
Java Code Examples for android.app.ActivityManager
You can also monitor the foreground activity to determine the Running tasks. Example here,
how do android monitor usage applications work
Lastly you can create your own service to detect each running process and their usage. A complete example of this procedure could be found here,
App to monitor other apps on android

Categories