Show alerts to the user if the app is closed? - java

I have simple app for show pageView with text, I want to notify user at specific time every day to open my app at specific page.
So I test my App by Marshmallow device, I am using alarmManager for this task, but once I close App from main screen notification stop showing.
I used Broadcast Receiver with remote process android:process=":remote" but Alarm not work also I used service also it killed with closing App.
So what is right sequence to achieve this job?

You don't need to use Service. AlarmManager and a BroadcastReceiver to restart alarm service on device boot.
Check this example:
http://stacktips.com/tutorials/android/repeat-alarm-example-in-android

When I was making alarm clock app for me Service with WAKE_LOCK was waking up the phone when it was blocked or the app was killed by user.
This class(with some notification displayed) is preventing app from being killed :
https://github.com/mrkostua/SmartAlarm/blob/master/app/src/main/java/com/mrkostua/mathalarm/alarms/mathAlarm/services/WakeLockService.kt
So after scheduled intent can be send to BroadcastReceiver.

Related

How to get broadcast receiver when an app is killed manually?

I am developing an app which records unlocks of mobile. But I am having problem when my app is manually killed i.e. when you remove app from recent apps. How can i record broadcast even when app is killed?
I am using ACTION_USER_PRESENT for recording unlocks.
You'll need to create a Service and inside this service create the broadcast receiver that you need.
This answer Certainly will help you : Implement Broadcast receiver inside a Service

Foregound Service start action from MainActivity

I am working on an Android fall detection application. When user falls, alarm with timer turns on and if user not clik cancel within 15s, app send SMS to contact. Everything works fine when app is open but I don't know how my foreground service should work. Is it possible to make foreground service work like that- after fall detected foreground service open application and run timer from Main Activity?
Code from foreground service opening MainActivity:
Intent myIntent= new Intent(this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
There are two obstacles to your use case:
Firstly, starting from Android 10, there are new restrictions on starting an activity when your app is in the background (and as it's written on the android developer page, even with a foreground service, your app will be considered in the background if no activities are in foreground). So you won't be able to "pop" a view to the user, except if you target a version < 29 (but it's not very recommended).
Secondly, since the beginning of 2019, the Google Play Developer Policy has been updated and you cannot use anymore the SEND_SMS permission, unless if you can justify in the publish console that your app is an SMS handler and you will need the user to register it as the default one. So you won't be able to send an automatic text message directly.
You can try to change the notification message to alert the user and try to have him click on the notification to open an activity.

How to prevent an Alarm from being destroyed even if the app is killed?

I read stuff about alarm manager on android studio and it seems to have a problem if the user intends to kill the app by means of swiping it on their respective task manager and also it is being destroyed if the phone is been rebooted. how am i going to retain the alarm then even if the app is destroyed? is there any other way how am i able to achieve this?
I'd recommend phasing out AlarmManager for JobScheduler, which has the ability to set it as a persistant alarm across reboots. It you're stuck supporting a version of Android without JobScheduler, you have to do it yourself by adding a BOOT_COMPLETE broadcast receiver and rescheduling the alarm on reboot.

Ignore phone silence mode

I'm building a security system for my office, which can be controlled via an android app. The app also should notify the user when an alarm is triggered by the security system. Therefore i'm using FCM push notications.
But how can i play a notification sound at full volume, even when the phone is in no-disturb or silence mode?
There is an app i used before, called "pushover", which lets our employees receive a push notification when the alarm has been triggered. They have a setting in their app "play high-priority notification sounds through alarm channel", which does that pretty well. But what does the "alarm channel" mean and how can i send notifications through it?
THere's different streams of audio in Android. One of those is the alarm stream. That setting would use the ALARM channel for this sound. This will not go through silence mode- the alarm channel has a separate volume control from media, but is still set to 0 if all sounds are off.
And you wouldn't do this through a notification. You'd do it through Java code in your app when the notification is received. But there is no way to force a sound if the user is in silent mode.

How to send notification even if app is killed

I am working on an Android project that has a part which dose this:
1) the user enter a data from a data field and save it in a text file
2) the app should send notification even if the application is killed by the os, at that date, the one wrote by the user.
For example:
I write 31.01.2015
The app will notify my only on 31.01.2015 even if i don't open that app anymore.
The question is how do i have to do this?
Thanks!
It sounds like you want a notification to be posted to the notification bar.
If so I advise using an alarm.
However, chances are if this is days in the future, the phone may be shut off. So you should store when the alarm should go off, create a Broadcast receiver for the on boot complete event (this requires a permission), and re-setup the alarm when the boot is complete.
This should allow the notification to appear, independent of the apps life-cycle, as long as the app is not uninstalled.
Note: You will have to calculate the milliseconds between the date for the alarm, and the current time. Calendar should help.

Categories