I am new to coding. I am using Android Studio with Java. I spent the last 3 hours looking for how to set up a notification display at the top when the user leaves the app so they can always click on the notification when they want to return to the app but I couldn't find anything with that action I need.
The app tracks the users GPS and I want them to be able to always be aware that when the app is running it will continue to track their GPS. So my idea is to have a notification window pop up whenever they leave the app so they can be aware the app is running in the background.
Any help will be much appreciated! I am building this app on my own as a passion project and I am taking the Udacity Google Android course. I finished the course early and working on this app for fun. We didn't learn about Notifications or GPS tracking but I am doing my best to learn new things. Thank you for your patience and help!
My app code is here for easy viewing:
https://github.com/PoetryHorizon/eloteroMan2
Use a foreground Service. For any background logic, you should be using a Service anyway, and in Android Oreo and above, you're required to have it be a foreground Service, meaning it posts a Notification.
You can then add a PendingIntent to that notification set to reopen your app. See Android's Notification documentation on how to set a PendingIntent. You'll want to use PendingIntent.getActivity(), where the Intent you pass is new Intent(someContext, YourActivity.class).
Related
I have a situation on my React Native app, where user can start a timer and isRunning and startTime states are stored in the app so that it can display current running time when the app is in foreground even though the user quits the application at some point and opens it again.
Is there a way to show notification icon on status bar when the timer is running, but user has quit the application to indicate that the timer is currently "running" (actually it is not doing any operations on background) on background?
I have encountered some apps that display a silent notification that is not directly closable after I have quit the app, but I haven't seen a situation where status bar notification is present (together with notification) until some condition is met after the app is quit by the user.
Is there a way to achieve this? I am using react-native-push-notification and Firebase to push notifications in my app overall.
React-Native manages only Active and Background/Inactive/Foreground state. When user kill the app. JS engine shuts down.
All you can use is Local Notification and Scheduled Notification. I also have one app in which user set a reminder time. And notification invoke at that specified time.
Using Firebase I guess you need to call api after some specific interval for push notification from server side.
I am not an expert in background services or android development but here is my thought... I believe you could dig in and write some java android code for a background unstoppable service (persistent on app close or background states). You can do this by creating a bridge and using native modules to manage your background services. I came across a great resource on medium that details the process of creating a background service, a broadcast receiver and maintaining Headless instance even when the app is closed or the device restarts.Hope that helps you achieve your goal.
Edit
This ready made package will help you with better. Check it out. You actually don't have to write native android java code at all.
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.
How does an Android alarm app or any other time based notifications app like Calendar, Clock, etc work? More specifically, how does it show up the notifications at exactly the time specified by the user? Does it constantly run in the background and as soon as the required time comes up, does it show the notification? Or does it schedule the notification in Android's kernel before exiting? I am working on an app that needs to give the user notifications at times specifies by him. I am not able to figure out how to do that.
Maybe what you mean is to create an alarm, you can see this example.
I am trying to develop an app that should run in the background. I want my app to pop-up a message everyday at a particular time of day. As i read i will have to use 'Service' for this. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle This link shows an example. But where should my code for pop-up be? I dint understand well from the above link. Another question i have is will the app continue to run even after a reboot?
you can show a notification from the app to show pop up msgs, that is the best practice. though showing dialog is also possible. code will be in service only. see this link
And to keep your application running after reboot you will have to register for BOOT_COMPLETED broadcast and whenever you receive that broadcast, you will have to launch your service again. see this link
I have just integrated services into my android app - I am also using startForeground because it's a critical app.
So, my question is - how do I get it to revert the user to the application when they have done a keyPress on the notification / service in their Notification Panel. I have looked everywhere for this and can't find it anywhere...There isn't much point in using services if they don't get directed back to the app onKeyPress so really need to get this working.
Any help is much appreciated.
Thanks
So, my question is - how do I get it to revert the user to the application when they have done a keyPress on the notification / service in their Notification Panel.
If the user clicks on the entry in the notification panel (via touchscreen or D-pad), the PendingIntent you supplied via setLatestEventInfo() will be executed. Use an appropriate PendingIntent to bring up the activity you seek. Here is a sample application demonstrating this.