Is it possible that if phone's screen turns off completely but phone does not go to sleep?
I have an app which do some things when device goes to sleep. I registered broadcast intent: Intent.ACTION_SCREEN_OFF
On my device app works fine ( HTC Desire, cyanogenmod ). When screen turns off, my app is activated.
I tried app on another phone (HTC Wildfire S, offical gingerbread ), and here is the strange part. When screen goes off my app is not activated (sometimes it is, like 10%). So i connected it with my LOGCAT and i wanted to see if device actually goes to sleep when screen is turned off, and the thing is that when is connected with my PC, device ALWAYS goes to sleep and my app is activated.
On emulators from froyo to jelly bean app works perfect. Is problem in my app?
From my testing of Screen Status broadcasts, I have learned that different manufacturers handle the screen off intents in different ways. Can't really depend on the phone.
You might want to use PowerManager to detect status of the device and take appropirate actions in onPause()
public static boolean isDeviceScreenOn(Context argContext) {
PowerManager pm = (PowerManager) argContext.getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
Related
I have app that is droping BLE connection in background after 10 minutes.
Everything works fine when app is connected to Debbuger if the device is locked while the app is in foreground the connection will be dropped after 10 minutes, but if we disconnect it and lock the device while the app is in Foreground , the connection is not dropped after timeout.
Are there some restrictions to Background execution when device is locked? Why does it work when connected to Debbuger?
Use Service in Foreground to create strong connection, it's the best option.
But even Foreground service doesn't help if Battery saving mode enabled, or another battery optimization modes.
Yes, debugger prevent app from being killed by system, actually not debugger but ADB connection. Sometimes test your application without USB plugged.
Also use PowerManager.WakeLock in service, it helps.
I have seen many pages about this problem but didn't help me.
I have a service that should run in background even when the screen is off.
but some android devices (like many huawei phones) have battery care stuff that can kill service when screen is off, and android 6 has that option (keep running after screen off) but user should give that permission himself.
I see that telegram service get killed too, but how whatsapp service doesn't stop even when the screen is off.
this is my service in androidManifest
<service android:name=".myservice" />
is there any option in manifest that can keep service running when the screen is off? I can't use sticky-services because it runs over and over after screen turns on but my service should start once!
or any other solution for this problem?? thanks!
I'm trying to discover Chromecast device on my network, select it and use for video streaming in a newly launched activity. It all works fine until I exit my "streaming" activity and return to "discovery" activity. I start a new discovery upon return to this activity and this time it is not finding my device (onRouteAdded() never called).
I call mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
in onResume() and mMediaRouter.removeCallback(mMediaRouterCallback); in onPause().
Is there anything else I need to do to restart discovery process? Note that I don't use MediaCast button and handle RouteAdded/Removed and selection manually.
Thanks.
I'm writing an app that needs to start up automatically when a device is connected to a tablet in USB Host Mode. In addition to that I want my app to start on tablet reboot after boot_completed if the usb device is attached. Having need to implement these two functionalities I'm in a bit of a dead lock situation. It works all fine when I plug a usb device the app brings up itself without a problem. but on reboot i'm running in to an issue where the application starts itself before the boot_complete is recieved, and that is because the usb device is already attached to the tablet. This is made worse in kitkat 4.4.2 as they have delayed processing the boot_complete state by doing it serially where as 4.3 did it parallely on reboot.
So how can I get the app to start on reboot after bootup is completed rather than before boot_up is completed while having the USB device attached.
Many thanks
I'm working on a simple camera application that will need to run for a long time, but take a single picture occasionally. The problem is the camera services goes to sleep or dies when the app runs for a long time.
When it goes to sleep, minimising the app and restoring it does the trick (as the camera is released onPause and opened again onResume). I've started my app from the CameraPreview sample which felt stable.
Other times the camera server dies (error 100) and I couldn't find a callback to listen for that. Rarely restarting the app resolves this, but most of the time rebooting the device is the only fix.
Is there a command to restart/relaunch libcameraservice without rebooting the device ?
If so, how ?