Using PassiveProvider and PendingIntents to ensure app location "freshness" - android

I was reading Reto Meier's (very useful) Android developer blog post A Deep Dive into Location when I read the following sentence concerning use use of the PassiveProvider and PendingIntents to help maintain a "fresh" application:
"If your app recognizes the concept of “exiting” (typically when the user clicks the back button on your home screen), it’s good form to turn off passive location updates - including disabling your passive manifest Receiver."
While I understand the need for apps to be "good citizens" in the Android community, doesn't this also defeat the purpose of using the PassiveProvider and PendingIntents to help ensure location freshness? From what I understand, turning off the passive location updates will prevent my app from receiving those updates. If this is the case, then when the user re-launches my app, wont they have to wait for another location fix? I know that I can call getLastLocation(), but I was just wondering how the PassiveProvider and PendingIntents help to ensure freshness when you explicitly turn them off when the app exits.

Well, I guess the answer is not so obvious :
there is no real way to close an application in android (for the user I mean). But the blog seems to assume that hitting the back button while in the main app screen/activity actually means to exit the app. This is, for instance, the way dolphin reacts to a back button hit.
So if people use this button, you can assume they want to quit your app and you can just close every resource you used, including passive location providers & receivers.
But, mostly, people will just hit the menu button and switch from an app to the other this way and let them all open. In this case, let your receivers in place so that your app keeps fresh as explained by Reto in his post.
Update : it looks like an official good practice to use back button this way (close app), this blog is quite interesting about it : http://www.androiduipatterns.com/2011/03/back-button-behavior.html.
Regards,
Stéphane

Related

Can an activity be invoked when the app is not opened from some pending intent without using notification or button clicks?

Note: I haven't coded anything but looking for a structure/keywords or ideas how it can be achieved.
Use Case:
I have an activity which basically shows some display/data/or does some operation etc when opened manually from button click, notification click etc. Now I want to display the same stuff when a particular condition is satisfied [like my geo location matches that I force to be my home or user home].
1. without user clicking any notification,
2. without opening the activity,
3. without clicking buttons, and
4. without opening the app.
So in short, I want my app to be launched when I am home or reach a geo fence, is it achievable?
I am aware of Pending Intents, but seems they need the activity to be opened once and register the intent, let me know if this is the only way to go.
Kindly help!
when a particular condition is satisfied
This is not possible in general. For example, Android has nothing built-in with the ability to do something automatically based upon when your neighbor's cousin's daughter posts something on Stack Overflow. Even though that is a particular condition that could be satisfied, Android does not know your neighbor, nor your neighbor's relatives, nor the neighbor's cousin's children, nor the online actions of your neighbor's cousin's daughter.
There are specific things that Android can handle that offer the ability to give you control for related conditions, such as AlarmManager for getting control at certain points in time, or JobScheduler for getting control periodically when the environment is proper (e.g., we have connectivity and are on a charger).
Your question uses a geofence as an example. The Play Services SDK offers geofence APIs that you can use, that can give you control when the user enters a particular region.
I want my app to be launched when I am home or reach a geo fence, is it achievable?
You are welcome to call those geofence APIs, providing a PendingIntent that points to a WakefulBroadcastReceiver, which in turn points to an IntentService, where you can go do something.
If by "my app is launched", you mean bring up one of your activities, while that is technically possible using an activity PendingIntent, you may make your users very unhappy for interrupting what they are doing (e.g., collecting Pokémon). Please consider using a Notification instead.
I am aware of Pending Intents, but seems they need the activity to be opened once and register the intent
Nothing of your app will ever run until the user manually runs your app (e.g., taps on your home screen launcher icon) or until something else uses an explicit Intent to start one of your components. At that point, you can call the geofence APIs, assuming that you somehow know where the user's home is.
Most likely, you need the user to spend time in the activity simply to collect the data from the user about where they want the geofences to be established.

Is it possible to turn on Location Services forcefully?

I'm creating an app, that heavily relies on LocationServices.
For now I'm asking user to turn them on, and everything works fine.
However, when user clicks "No", the whole point of this app goes to hell.
I can spam user to turn location services on from my Service, however I find this solution extremely non-elegant.
Is there a way to turn this setting on programatically? I don't care for additional permissions or so.
I did my research and I only got what I already did - ask user to turn on location services with a dialog etc.
Is there a way to turn this setting on programatically?
Fortunately, no, for obvious privacy and security reasons, except perhaps on rooted devices.
However, when user clicks "No", the whole point of this app goes to hell.
Then advise the user once (per run of your UI) that your app cannot function, and the user should uninstall your app.
Bear in mind that many more permissions will have this same sort of user-recovable behavior with Android M.
You simply cant , if that was possible then you can easily gather locations which is for some unethical reasons could be sold ... so for security reasons its not possible at all .
you can always force the user to click yes by making a really useful and helpful application that the user simply want to try and cant click no because it wont function at all ...

Design of website pushing info to the app, or app retrieving from website

I have a design question about Android app and I am not sure if I can ask it here (If not please advise when I can ask).
I want to make an app where it gets information from a website (or actually make the website push locations to the app). Imagine a webform that has 3 fields (3 trucks locations). I want that everytime I put those values and click submit, The android app on the devices will show the location of the trucks on the map. I am familiar with the google maps so I know how to show 3 dots on the map given the location. I also know how to write HTML code that would do POST/GET upon press of a submit button But the communication and how to initiate this trigger on the app is what I am confused about. So it is more of an architecture design question. I need a starting point to know where to start looking. I hope I delivered my point here.
sooo Any help ?:)
Your talking about setting up push notifications, look at http://parse.com/products/push
This may be a use case for using Google Cloud Messaging (GCM). I have not worked with GCM yet but this is one option.
Another idea is to setup an AlarmManager to schedule the fetching for data. One draw back I can think of is if you set the AlarmManager to be frequent (ex: every 10 minutes) then all those network requests are going to drain the battery quickly.
Another alternative and similar to the polling, is to have a button within the application where the user manually presses to get the latest data.

Possible ways of programmatically/normally securing settings tab on lenovo tablet? (Includes android programs to password protect it)

I would like to secure settings tab on lenovo tablet device with a password. What is a simple way of going about this? Code is welcome too (I think I might need to code but if you think an google play marketplace app would solve my problem please post your suggestion below).
Edit: I have researched and posted on lenovo forums already which I always do before posting here and it takes them a week just for simple question sometimes to respond.
Please if iam too vague say so below because -2 does not help me one bit.
Here's more more information for why iam trying to do this:
I work at a K-12 system with high students always testing my wits.
Without the password kids/students can add their own account or change settings for the tablet doing things that could hurt the school system legally (download playboy, using the devices to distribute viruses and malware, and the list goes on
Unfortunately for the purposes of what you're doing, Android doesn't really allow for keeping the "primary user", so to speak, out of the settings application. I'm not personally aware of any existing "lock" type applications, but they might exist; you might be better off asking on Android Enthusiasts for that.
There are a few hack-y type things you can do programmatically, however, without modifying the OS. The one I've seen work the most effectively for similar tasks is to code a Service with a Thread more or less continuously polling the ActivityManager for a list of running tasks (getRunningTasks()), checking on fixed intervals (perhaps once a second?) then, if the unwanted Activity is detected in the foreground (I believe that the Settings app component name is android.app.Settings), Launch a Password Activity. If the user successfully authenticates, simply finish() the password Activity. Otherwise, start the home activity (effectively clearing the Activity stack) with an android.action.HOME intent

Android: Proximity Alert

I have followed this tutorial about how to use the proximity alert and how to register it.
It all works but when I close the app (with the back button, not the home-button) then the proximity alert does not work anymore. Does anyone know how to set it so that it runs in the background?
Thanks in advance!
It seems that you can not get location updates when your application is not running. Receiving location updates in the background is not a good idea since it drains battery power and the user might not be aware that the location is being tracked since the normal behavior for pressing the back button on the application is for it to close all services. If I want my application to continue running in the background, I as a user would press the home button.
Look at the model used by the "My Tracks" application.
Also see the documentation from Android on locations and usage models:
http://developer.android.com/guide/topics/location/obtaining-user-location.html
If you have informed yourself about the reasons not to have the application do this in the background but still want to run this in the background, look into Services
http://developer.android.com/reference/android/app/Service.html
They can run in the background and provide your application with data when asked.
Fundamental part of Android... Services.
http://developer.android.com/guide/topics/fundamentals/services.html
You should get it if you register for it, but keep in mind that proximity alert may not be immediate if your screen is off. If your screen is off, then location is probed for every 4 minutes as stated in the documentation.

Categories

Resources