bring the activity front of all the running application - android

I have developed an alert reminder type application, so when alarm is called my broadcast receiver call one activity and fire one notification and also start one service, it working good,
But when I working in other application some time the my service and notification is fired but activity is not open. it happen sometime not all.
So, how can I give the priority to my activity so it can open always if we working on other application, just like in call receiver screen.

I think you cannot bring your app to top when other other apps are in front. The call receiver screen is system window which has special privileges. You cannot have the same for your app.
As a alternative you can fire a notification to status bar.

Related

Deep link notifications not working in android 12 (Not opening the app when user clicks on notification)

It was working fine, the app was also in production. But recently we noticed that on android 12 when the user clicks on the notification it doesn't open the app and navigated the fragment/activity which the deep link has.
But as soon as the user opens the app the deep link gets fired(if the user has previously clicked on the notification then) and moves user to the destination which was in the deep link. And also if the user is in the app and clicks on the notification it will work fine. But if the user is outside the app it doesn't work in that case. We also tried to upgrade the firebaseBomVersion to the newest version (31.0.2). But nothing seems to work.
There are online other post related to deep link not working on android 12, but they all have are having different issues.
Does anybody know anything about this issue?
So, in the end, the problem was this
system_process E/NotificationService: Indirect notification activity start (trampoline) from com.xyz.debug blocked
On android 12 and above we can't start activities from a service or from a broadcast receiver on a notification tap (which is what I was here doing), I was trying to start an activity from the broadcast receiver, and I was firing that broadcast when the user was tapping on the notification.
When users interact with notifications, some apps respond to
notification taps by launching an app component that eventually starts
the activity that the user finally sees and interacts with. This app
component is known as a notification trampoline.
To improve app performance and UX, apps that target Android 12 or
higher can't start activities from services or broadcast receivers
that are used as notification trampolines. In other words, after the
user taps on a notification, or an action button within the
notification, your app cannot call startActivity() inside of a service
or broadcast receiver.
When your app tries to start an activity from a service or broadcast
receiver that acts as a notification trampoline, the system prevents
the activity from starting, and
Documentation link
How did I solve the problem
simple, I used the same code, i.e. adding a broadcast to the pending intent and attaching that pending intent to the setContentIntent() on the notification for android 11 and lower devices but for android 12 and higher devices I replaced that broadcast to activity intent (an activity with transparent background) and in that activity, I placed the same broadcast code which I used for android 11 and lower devices and then using sendBroadcast() method I fired that intent myself and after that finished that activity.

How to trigger pop-up in app via notification click even when app is not running

I'm trying to implement a timer in my app. The timer runs in a foreground service, and it works as intended.
Upon clicking the the notification, it should a) open the Timer activity (which is the Main activity) and b) open a one-time pop up asking if you want to stop it. (not the full extent of the pop up, but I've simplified it for this example).
I am having difficulty with this functionality because of a few challenges/limitations. My two main methods is using RxJava and broadcast receivers via Pending intents.
If the app is open and in the foreground, I can use an observable via a broadcast intent and listen to it the Timer activity. when it receives a value, it shows the pop up. Simple.
If the app is closed or in the background, I've tried using a pending intent with a key-value extra such as ("should-show-pop-up",true). I then check in the onStart method if this extra exists and if true, show the pop up. However, now it shows the pop up every time I open the app. If the app goes in the background and then back to the foreground, the activity still holds that extra and it triggers the pop up.
So bottom line: how do I open my app and show a pop up if a user presses a notification? Even if the app is closed or in background
Best way to do this is to use a separate Activity for this not your main Activity. When you create the Intent to put into the Notification, add the following flags:
Intent.FLAG_ACTIVITY_NO_HISTORY
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
This will ensure that the Intent with the "extras" does not become the "default Intent to use when your app is launched from the HOME screen"

Do not want to keep a launcher activity in BroadcastReceiver

Creating an application in which whenever Power is connected or disconnected a small ringtone is played.
But the problem that i am facing is that the application is not working whenever i am not taking any launcher activity.
And when there is a launcher activity than the application is working well.
Sigh..vague and no code :(
Android does not allow BroadcastReceiver to receive some broadcast info if the appĀ“s process is not alive.It was designed to against the evil apps. If you have an activity running,your process is alive and so your receiver is allowed to receive the broadcast.
You can make a transparent activity and use startService to start a service in background,then finish the activity.As your service is running ,your process is alive,so the Android will let you to receive the broadcast.
The rest of your questions can be directed at the offical docs.

when alarm fires, start an activity if app active or send notification if app not active

In my app I want to schedule an Alarm associated with Activity A. When the alarm fires, what should happen depends on the circumstances:
1. if the app is not opened at that time, then display a notification in the notification bar and also start the activity A the next time the app is started
3. if the app is active, start Activity A
Activity A is not a background activity - it requires user interaction.
Ideally, the same behavior would work with more than 1 alarm - i.e. if 2 alarms fired while the app was not in use, two activities would be queued to start once the user starts the app.
I read the Android Docs on AlarmManager, PendingIntents and Notification - I know how to schedule an alarm which fires a notification, but I don't know at all how I would go about
- the "queueing" of activities after an alarm fires
- the "conditional behavior" when an alarm fires (based on whether app is running or not).
It seems like plenty of apps would need this kind of behavior. I hope someone can point me in the right direction.
Found a solution in the "Android Programming: The Big Nerd Ranch Guide" book (Hardy & Phillips). The solution is to use Intent Service that handles the AlarmManager intents, and sends an ordered broadcast. The broadcast is either received by an Activity, or - outside of the app lifetime - by another service, which then sends a notification.

Bringing my Alarm to the front

I had a few problems with my alarm that are in a another thread here if anyone could help but anyway here is a new question. If I set an alarm using my app, say for 5 minutes from now, and then close the app, how would I code it so that my app activity comes back to the front?
This is basically the same as the clock app already on most android phones. I'm doing this to allow the user to stop the alarm. Would I be right in saying that I would have to modify my existing code to, when the alarm is run, launch a new intent to bring the activity to the front? Or can I simplify this and only have an alertdialog or something open instead of opening the entire app?
Any links would be appreciated
Thanks
Don't move your activity to the front automatically. It's as annoying as a pop-up ad! Do you really want to try to interrupt the user who's trying to look up a phone number?
Instead, use a Service. When you want to tell the user something, post a status bar notification. You can set up the notification to bring up an Activity when the notification is clicked.
Most alarms are implemented in a Service.
Have you looked into the AlarmManager? http://developer.android.com/reference/android/app/AlarmManager.html. I've used it in the future to fire Intents for Notifications. The Notification can then open an Activity for the user when they select the Notification from the Android Notification Bar.

Categories

Resources