All, in my new android application i need a notification to trigger if the app is not used for last four days. That is from the last use of application if 4 days gone and not using the application a notification need to come.
plz any help will be apreciated...
thanks in advance.....
You will have to manage it by yourself.
1.) Set a preference to the time you want the alarm to go off, it will save, even after reboot.
2.) you need RECEIVE_BOOT_COMPLETED permission and register a BroadcastReceiver in your manifest for the BOOT_COMPLETED
3.) just reset the alarm time to the time you need, from the preference.
I think that's very bad practise... but if you want to do it nevertheless, simply use AlarmManager.
Related
I am trying to find documentation or a cleaner way of not showing notification(programmatically) during nighttime (sleeping hours). I have a service that periodically checks if certain conditions are met and then I fire the notification. I would want to avoid this when the user is sleeping.
I don't really think you need to. If the user wants to block notifications, they'll put the device in Do Not Disturb mode which blocks all notification. I have one set to automatically turn on at night and off in the morning. Bonus- when the DND turns off, I get all the notifications I miss. This is a feature of the Android OS.
If you really wanted to do this- just check the time before you put up a notification. If its too late, don't fire it. Optionally, set an alarm for when you think its late enough, and decide if the user should see them now.
Do you mean to keep running the program at night without using notifications?
You only need to use WorkManager, JobScheduler or AlarmManager to achieve.
In my application i need to deploy a some kind of reminder. that every day at any fixed time my application generate a notification..
and it happens if my application is running or not. (e.g by using background service)
I am able to generate notification, but im un able to create logic to generate it every day. Please help if any one understand what i want. Thanks in advance.
See below link and this is work for me.
Create alarm set on a specified time, using AlarmManager
Repeat alarm everyday accurately
I'd like to know if it is possible to create a notification or toast/alert from my app when another app is opened. For example, my app Foo will create a notification if Facebook is opened.
Edit: What I actually want is to inform the user that my app is running in the background when the default camera app opens/running. My app will modify photos taken with the default camera app when it is running in the background and I want to inform the user that it will do so. Is this possible?
Basically what you want is a push notification. Please go through following tuts to help yourself:
https://neurobin.org/docs/android/push-notification-gcm-client-server/
https://developers.google.com/cloud-messaging/android/start
Yeah, you can take a look at this and then schedule an alarm using some background running process that looks for Facebook being running.
One way is to use AlarmManager to check running apps every 5-10 mins and you can generate a notification if your condition is met.
I am new to android. I am making an alarm clock. Its working perfectly until the user clears the app from the RAM. On searching, I found that broadcast receivers don't work if the app is cleared from the RAM. So, what exactly should I do? Will sending the broadcast from a service help? Also if you have a link to a good tutorial to Services in android, pls do share. Also let me know if there is some other way to solve my problem.
In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below:
Open Security app on your phone.
Tap on Permissions, it'll show you two options: Autostart and
Permissions
Tap on Autostart, it'll show you list of apps with on or off toggle
buttons.
Turn on toggle of your app, you're done!
You can register broadcast receivers either inside the activity at runtime or in the manifest. You want to adopt the latter approach
In the past I have similar problems with AlarmManager, AlarmReceivers and this kind of things. There are some tips that can help you in your code:
Make sure that you are scheduling your alarm correctly.
Make sure that you are setting the propers permissions on the manifest.
Take care if the device is locked or it was rebooted.
There is a quite useful tutorial that helps me to control and make a "Hello World!" example with AlarmManager: AlarmManager Repeating Example
Note: In API 19 and higher, the method setRepeating is not exactly (maybe the alarm triggers at 10:00 or at 10:15), so you must use setExact.
Hope it helps!
You can register broadcast receiver in two ways
1. From your activity.
2. From your manifest.
if you registered broadcast throught activity, It wont receive after your activity is destroyed, So thats is where we register BroadcastReceiver in manifest.
This link will help you BroadcastReceiver
I checked almost all questions in stack overflow and also in google documentation and still couldn't understand what to use exactly for my cases.
What i want is, user will select reminder date in the app and in that time app will send a notification even app is closed or phone restarted between remind set time and remind time.
So what do i need to use? Which classes do i need? Broadcast Receiver, AlarmManager these two is enough or what? a sample of code 20-30 lines would be nice =)
You will need both a few things.
Setup:
You need to set your app to listen for the phone starting by registering for this intent in your manifest.
Basically you when your user selects the time, you will need to:
Save that time in a file/db/shared prefs.
Set the alarm manager to wake up your app at the right time
When the alarm manager sends
you a broadcast, start a service to do the necessary work (broadcast
receivers have to complete their work in a short amount of time, so
it's better to start a service)
In your service, remove the time
from your file/db/shared prefs
If your app ever gets the broadcast that the phone was rebooted, then all of your alarms are lost. You need to reset them using the times you saved in the file/db/shared prefs.
Check Android Developers website for calender intents so you can use them to determine the time etc.
On your broadcast receiver pass the details or timing to the broadcast receiver. Once you do that use the alarm manager etc to check if the time is perfect and simply send a push notification when the time is correct.
I say this assuming that you know already about the calendar, alarm manager, and broadcast receivers intents. If you don't I recommend googling the following with Android Developers appended to it.
Use AlertManager.set to send notification on particular time.
For re-setting Alarm Notification, use
<receiver android:name=".AfterBootReceiver" android:label="AfterBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
and
#Override public void onReceive(Context context,Intent intent){
...
}
to reset AlarmManager.set after device re-booted.