I am new to Android and have a problem with the Notifications. I know that this topic has been taken up earlier as well but I just wanted to know if there is any other way to go about it.
Problem : In my application I want that the user is notified that he/she has entered in the radius of a particular location. I have the functionality working when the application is alive and in the foreground. I will however want that the user is also notified when the application is not working and not there in the foreground.
In the previous posts I have found out that this can be done by using something called as the C2DM. Altough I am not much aware of it but by using C2DM I would be introducing an extra network trip. My question is that the only way to go about it? Can't this functionality be done any other way round, something locally like something of a daemon thread of sorts?
Also if C2DM is only the way, and as my application is not in my foreground will the C2DM also inform once the user reaches the radius of a particular location?
Will like to thank you all in advance. Please do let me know if any one of you have faced a situation/problem/requirement similar to this before and also if you can highlight the way forward for this?
I have the functionality working when the application is alive and in the foreground. I will however want that the user is also notified when the application is not working and not there in the foreground.
Use addProximityAlert() on LocationManager, and then it will not matter whether your app is in the foreground or not.
Related
I am creating a demo for android and for that, I want to not show notifications for a specific application like WhatsApp, Facebook, Instagram, etc. And for that, I have added notificationlistner and it worked for me when the application is in the foreground or in the background but not in a killed state. And I want to make it happen in the application killed state.
It would be great if I get help with this.
I have a simpler answer for you- just don't have those apps on the phone you're using to demo. If necessary, buy a cheap used phone for your demo. Far less time and effort than trying hacks to make notifications of other apps disappear.
I would like to get a list of users connected to internet and set their status as online. I am using Firebase Presence for it but it only works when the user in the application. When the user closes or minimizes the app, the status is set to offline but I want to keep the status online as long as the user has an active internet connection.
Note: I am using Android 8.0 and I know about limited background services.
How can I achieve this? Thank you.
Android may kill an app's process when it's no longer being used. This is something you should expect to happen. When that happens, Firebase will obviously lose its connection, and the app will be considered offline.
The only way to extend the life of your process is to start a foreground service in your app that stays active indefinitely. Even then, Android may still kill your app to make room for apps that are visible on screen. There is no way to guarantee that your app's process will never get killed for something more important to the end user.
Please read this documentation thoroughly to understand how Android prioritizes apps. Also read the documentation for Service.startForeground().
I'm wondering if you can launch a given Instant App based on the user's location. Is this kind of thing possible? I suppose it would require some kind of server to be always running on the device.
Edit: To clarify a bit, this would be like if App A has a service that tracks the user's location and if they go to a certain spot it would launch Instant App B.
Thanks!
it would need a constant running service and launching the app might be a problem since this particular function could be ransomware like but a notification could be instead that's.
beside that it would a continuous location request at all time.
I'm trying to figure out the right way to add Chromecast buttons (pause, play, etc) to an Android Notification. I've set up a custom notification that sends PendingIntents to a ChromecastService. That service is trying to interact with a class I built called ChromecastAdapter. The ChromecastAdapter implements MediaRouteAdapter and contains all the listeners and state that go along with casting. However, all this state is gone as soon as I exit the application. So, my ChromecastService doesn't end up having access to the Chromecast once my app is gone.
It seems to me that the only way to get this to work is refactor all the Chromecast state into a Service that implements MediaRouteAdapter. I really don't want to do this since I'm pretty happy with the way things are now.
Since these interactive Notifications are required by Google, I feel like there has to be a standard way of interacting with a cast from a Notification. Am I on the right track here? Do I have to place all my Chromecast interactions behind a Service?
What the behavior should be depends on the type of app and the requirements of the app. If your app is "gone" (in the sense that the Application instance is gone), then the question that you should ask yourself is whether you would want to keep a notification mechanism to stay around; there are apps that when they are killed, the receiver also gets closed and user is sent back to the home screen on the chromecast device, in which case there is no reason to keep a notification around.
On the other hand, there are apps that based on their requirements, you would want to let the cast device continue what it was doing (for example play the video) even if the mobile app is gone. In those cases, you may want to have a notification mechanism in place for "bringing up" the app. To achieve that, you need to maintain certain amount of information/state/objects in a service, enough to be able to establish a connection again and "join" the running app. In addition, your "service" needs to be aware of the status of the app on your receiver so if that app is killed (say, someone else starts casting a different app to the device), it can be notified and exit.
I am writing a metronome app, I have the sound running from a service which I would like to keep running when the user is outside the app (browsing etc) and hasn't made a conscious effort to press the stop button.
It seems I should be using startForeground() as it's not the kind of thing you want in the background without paying attention to, and I really don't want the service to be killed at any time. Ideally I wouldn't be showing the notification while the app is in focus though. I notice that the Google Play Music app works this way, it only shows the notification when outside the app. Is anyone able to tell me how they have done this, I would find it hard to believe they wouldn't be using startForeground() after reading all the documentation stating you should be using it for this sort of app?
On the other hand, is this really desired behavior? It seems good to me, but I noticed that pretty much every other app I use with a long running service (HTC's music app, Navigation, few others) shows the notification icon at all times, whether in the app or not. I am interested in what is considered correct behavior. Any help much appreciated, thanks.
Is anyone able to tell me how they have done this
They probably call stopForeground() when one of their activities returns to the foreground, and startForeground() when they think the user has left (e.g., onUserLeaveHint()).
I am interested in what is considered correct behavior.
I do not think there is a definitive "correct behavior" in this area. It is easier to do what the other apps do and leave the Notification around, until the user indicates that they no longer want the background work to run.
Note that while you may want "to keep running when the user is outside the app", the user might not. Certain types of apps (e.g., music players) can safely assume that the user wants the audio to keep going; a metronome, IMHO, does not rise to that level. Please allow the user to configure this behavior, such as through a SharedPreference.