Android OS blocks my network packages - android

My App sends out GPS data with a timer. Sometimes I block the screen.
Now with some phones and only sometimes I have the problem that the OS somehow blocks the data packages and only releases them later, when the screen is unlocked. The messages still are getting sent from the app but only stopped in android.
Anybody have a Idea why that happens and how I can stop it?

Is it possible that those devices are going to sleep (or sending the radio to sleep)? Have you tried setting a wakelock to prevent this? https://developer.android.com/reference/android/os/PowerManager.WakeLock.html

I suspect your application goes to sleep, or your wifi. There are applications specifically designed to keep your wifi alive, so i suspect it does sleep. Were i to create the wifi, i would definitely make it sleep when there wasnt anything to say.
To test download one of the apps. That and write to a log file when your application is going to sleep.
Sorry i couldnt give a specific answer. Id have posted this as a comment, but im too new to be able to do that.

Related

capture hard-button events when phone is locked?

i am currently collecting information, if it is possible to make some kind of quickdraw-application for emergency purposes; i want to get the device to start a customized camera-intent once some certain key-combo is pressed.
I have check quite some information on the topic already, but it is still not clear to me how doable this whole idea is.
So far i figured, that it is not meant to be by android-design. My first idea was to build some kind of InputService and make it teach the hard power-button to listen for a triple-click. But the Services arent allowed to catch KeyEvents. So, the volume-button is out of the equasion aswell.
Then i came across the idea reacting on the SCREEN ON/OFF event, but 80% of the ppl say that it is not going to work, while 20% state, that they got it. But im not really sure if they really did it.
Last but not least the question, if it is possible to launch this customized-camera-intent/application out of the locked mode.
resumé: i need to check if its possible in general to launch this camera-app (that does some quick fotos for emergency purposes) while phone is in the pocket in lock-mode. Anybody got some opinion for me? thx
The solution is to setup a BroadcastReceiver that is listening for the SCREEN_ON-Event. I did this one inside a backgroundservice that was waiting for at least two SCREEN_ON-Events within a short period of time. (less than two events obviously can't work)...
The Service then dismissed the Keyguard and was able to even pass past password/gesture and run the App. Funny fact: closing the app does pop back to desktop still beeing logged in.
I did this at Android 4.2.. Sources told me that dismissing the keyguard is not working with current Android-versions no more.

Running app while the device is off

I have a very simple question. Can you force an app (from a development point of view) to run while the phone is off and plugged in. I know with my phone there is a battery display that shows while the phone is off and charging which I assume is controlled by software but I was wondering if that is possible with an app. After research my gut is telling me no but I want to make sure.
I know with my phone there is a battery display that shows while the phone is off and charging which I assume is controlled by software but I was wondering if that is possible with an app.
This is not possible from an app, only from firmware.
If you are not looking to update the screen, you can use a WakeLock to keep the CPU on. Or, use a different WakeLock and keep the screen on all of the time. Neither of these will make the user very happy, unless it is done completely under their control.
You will need create Service and on create or when you are about to do whatever your app does, create and acquire WakeLock. Once it's done you can startForeground to let user know that you are doing some important job and let Android to keep you alive/process and let your app finish work.

How to restrict users to shut down apps on Android?

I have a request on developing enterprice tracking application. The application should be able to get current postion of the phone and send it to server every 5 minutes. Even if application is running on background - user can easily shut it down. I need to create some sort of restriction for that, maybe password based. In order to shut down this application user must enter a password. And if he is rebooting, application should autorun after rebooting.
Is it possible to do this?
No it is not!
But... I know a trick that can do the work, it's name is AlarmManager
You can set alarm for your application that will alert every 1 sec, and if the application been shut down it will rebuild it self.
At this point you can set a password to shut down the alarmManager.
But just to let you know, I been trying this once, Google told me nothing, but users left me a comment that the application is hacking they device ;)
From ICS onwards, any app implementing Device Administration cannot be stopped. But the only drawback is the user can remove the Devvice Administrator.
You could restrict your app to work only when Administrator is On.
One more way is if the user removes the administrator you can lock the whole device with a custom password using resetpassword.
If the devices were rooted you could implement that but you probbaly wouldn't be able to distribute the app as an APK due to the required modification of system files. Maybe as a Zip that is flashed via Clockwork mod. Beware of voiding the devices' warranty though.
Babibu's suggestion regarding Alarms is a novel approach, but be cautious of waking the system constantly as that will drain the battery much faster.
Actually a big problem you'll face is that the user can disable GPS and then you can't programatically turn it back on again - unless you try to use an exploit which is obviously not ideal and won't work on all devices.
A better idea might simply be to report to your server whenever the user disables the application or GPS. You'll know which user disabled it so your organisation can punish that user appropriately.
What you are looking for is Device Administration
http://developer.android.com/guide/topics/admin/device-admin.html
This page explains how it works and how you can change all sort of policies about passwords and disable camera.. et cetera
What they barely talk about is as soon as an application is enabled as device administrator you can't kill it or uninstall it without disabling this feature first. It's up to you to implement enable/disable buttons the proper way.
To be sure the service always restart even if killed by system (in low ressources cases) you need to override this method of your Service :
public int onStartCommand (Intent intent, int flags, int startId)
{
return START_STICKY;
}
Finally to make your service start at boot you need to catch ACTION_BOOT_COMPLETED broadcast.
The main issue is you can't prevent user from disabling GPS or using mock locations but you can detect it and log it.
It is a good practice (actually it is mandatory in my country) to notice users they are watched so you can explain them at the same time that you'll know if they mess up with the GPS.
Rooting the phone is another solution but you will likely open more doors than you close ;)

background service makes app crash after unlocking the real device

I am running a background service which checks for some updates from the server every 2 hours in my android app and it works fine so long as the device is the not in the locked state. But once I lock my phone and unlock again I see my device displaying the message that my app has crashed. What could be the real reason behind it. Does it need some permissions to be declared. Could anyone suggest me as to why this is happening.
It can be happening from several causes. But I gonna give my guess: are you taking in consideration the case that your app fails to reach the server? What I mean is that I'm guessing that when you lock your phone, or close it in some way, it can be closing your connection and your app can be crashing because it fetchs the server without connection. Its only a very broad guess...

Application for Child Monitoring

I am starting an application for child monitoring. This would involve mainly the logging of the SMS messages sent and received and logging other activities that may be of interest to the parents. It will also be nice to have something like access control lists for these, too.
Now, as far as I know:
It is not possible to make an app "not uninstallable".
It is not possible to prompt for a password to uninstall an app.
It is not possible to assure that your app is "always" running even if it's getting killed with something like Task Killer, although I think you can respawn the application at given time intervals.
So, any ideas on how to overcome these problems?
There is no way to work around these problems directly without creating your own build of the Android OS. Android always assumes the current user is the owner of the phone and should always be allowed to do whatever they need to do.
It's easy to see why the functionality you need isn't available if you replace "child monitoring" with "malicious data logging" in your question; if Android allowed an app to prevent the user from removing it, it would clearly be open to abuse.
The only thing I can think to do is to have your keep a log of when it is running. This would allow a parent to seen when the app had been running when they viewed the log of the collected data. So if the child had disabled the app the parent would know, but they wouldn't know what had been missed. Although you'd had to be able differentiate between when the phone was switched off and when the app just wasn't running which might not be straightforward.
What you said is true.
Also remember that applications like Task Killer have some sort of blacklist/ignore list so re spawning your app might not make it work.
PS: Without a rooted phone, there is no way you can save your app from a geek kid :)
I was thinking about writing a similar app and considered the same exact scenario. "What if the kid uninstalls the app?"
The only solution I was able to come up with was to have the app periodically ping a server with the a unique ID. Affectively having the app "Check in" with the server a few times a day. Kind of like when prisoner goes on parole. The app is the prisoner and the server is the Parole officer :)
If the app misses a checkin you could treat this as a potential uninstall. However, this could be caused by a lack of network connectivity. I'm sure you could come up with some interesting ways to flag and treat missed checkins. Maybe you could have the app send an SMS checkin or something instead of over HTTP. Then you wouldn't have to depend on Network connectivity.
Once you figure out how to translate missed checkins to an uninstall, you could shoot out an email to the interested party (i.e. the kids parent).
With this option in place, the parent can then have a "Conversation" with their kid before giving them the phone. Something along the lines of:
- "This phone's got parental controls on it. Yes, you do have the ability to uninstall them. However, if you uninstall them I'll know about it and I'll take the phone away."
I think there's definitely a market for this. Need some type of web-interface/dashboard for that parents can log into for monitoring too.
Hope this helps & best of luck.
Cheers!

Categories

Resources