I want to continue running my application when the back light and screen lock. Is it possible or not. Anybody kindly guide me?
timer Function
receiver
are running in Background. Inside the receiver I am getting the Data.
If you are using Timer to manage your Application, I would insist that you should use AlarmManager which is an inbuilt Android Facility that Android knows better. In Timer the problem can be that when Android seeks resources for any other Application or something like that it may kill your Timer thread and get the resources where as it won't kill the AlarmManager service that is running because that is what Android knows. You can check my question here to get further idea.
Here Code tht will help you
KeyguardManager mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("activity_classname");
mLock.disableKeyguard();
And this is the Reference Link
Following source will help you to unlock the screen.I hope this will help you a bit.
KeyguardManager mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("your_activity_name");
mLock.disableKeyguard();
Related
I want to check programatically if my device is locked by a third party Lockscreen...With the normal Lockscreen by android you can do that by
KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = kgMgr.inKeyguardRestrictedInputMode();
But what if a third party Lockscreen is installed?! Is there any way to check if the device is locked?
You can get the foreground app and check for its permissions using the PackageManager class.
To get the foreground application you can go through this link.
Once you get the foreground app, you can fetch the permissions of that app. Check this link for this functionality.
Later, You can check whether its a system app or not by going through getApplicationInfo and later & with ApplicationInfo.FLAG_SYSTEM. You can check this link on how to do that.
I think that all custom lockscreens use the <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> permission. So your method should be correct in most of standard cases.
How can i read the settings for my ScreenLock in Android ? Whether the scree lock is
None / Slide / Pattern / PIN/Password lock ?
I can find only one API to know whether it is pattern lock or not .
Thank You
Check out a similar question asked here. Use KeyguardManager to check if the device is locked.
KeyguardManager kgMgr =
(KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean showing = kgMgr.inKeyguardRestrictedInputMode();
i a'm completly android programing noob
i'am working on developing "Androrat" (this project is not mine i had found it over the internet)
when the screen turns off the connection is lost
how can i make the processes/service always running ?
I had googled some and found that i have to include a partial_wake_timer
I want the code and where i have to enter it ?
I a'm completely noob please bair with me
http://dl.dropbox.com/u/102520949/Untitled.jpg
or maybe a kind person can help me over team-viewer ?
A partial WakeLock is what you want. It will hold the CPU open, even if the screen is off.
To acquire:
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();
To release:
wakeLock.release();
This answer was taken from this link:
How can I keep my Android service running when the screen is turned off?
Next time, please search more deeply.
I'm trying to make an App on Android 2.2 that has to run whether the screen is on or off.
I tried realizing it via a Service, but when my phone turns the screen off the service stopps working and I don't understand why.
In my Application I use
startService(new Intent(this, MyService.class));
when the User presses a button
and
Notification notification = new Notification();
startForeground(1, notification);
in the onCreate-Method of the Service class
(I tried it within the onStart() Method, too)
(I also could not find out what the id-field of startForeground() expects so I used the 1)
The service then should start an infinite vibration pattern of the phone so I know whether it is running or not.
But when I turn off the screen, the phone stops vibration immediately
Please help me. I don't know how I can fix that (and google was not a big help)
Sincerely
zed
Android devices go to a sleep mode when idle (e.g. when the screen is off), in order to conserve the battery.
To keep your service running you need to aquire a WakeLock. There are plenty of tutorials how to use it, like this one.
Note that having a service running all the time will drain your battery. Also make absolutely sure to release the wakelock when not needed, otherwise you're phone will always be awake.
Try returning 'START_STICKY' from 'onStartCommand() '. This will keep the service running, restarting it if necessary, without keeping the screen on.
Have a look at http://developer.android.com/reference/android/app/Service.html#START_STICKY
try this
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
and in manifest file
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
so when your notification or alarm manager service running, screen will light on and the keyguard will unlock.I wish it works for who has this problem too.
Here's my scenario. I have an app that is playing backgound sounds. Using the BroadcastReceiver I can tell when the display turns off, and then kill the sounds. I can also tell if the screen turns back on. However, if the device is in the lock state I don't want the audio to start. Therefore I wait for the ACTION_USER_PRESENT intent to signal. That all works, except that if the user turns the screen back on quickly after it was turned off, you don't get the lock screen or the ACTION_USER_PRESENT message. So, is there a way to tell, when the screen turns back on, if the device is locked or not, which I guess also means sleeping or not?
((PowerManager) getSystemService(Context.POWER_SERVICE)).isScreenOn()
You can try the KeyguardManager to check if the device is locked. Here is some code (I haven't tried this myself):
KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean showing = kgMgr.inKeyguardRestrictedInputMode();
Good luck!
Satur9nine's solution was right at the time, but since then isKeyguardRestricatedInputMode() was deprecated. Some powerManager related functionalities are now deprecated as well.
There's a newer, more accurate solution: isKeyguardLocked() for whether the device is locked, and a different approach to obtain whether the screen is interactive; You're looking for a combination of both.
KeyguardManager appKeyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
PowerManager appPowerManager = (PowerManager) getSystemService(Context,POWER_SERVICE);
boolean showing = !appKeyguard.isKeyguardLocked() && appPowerManager.isInteractive();
((PowerManager) getSystemService(Context.POWER_SERVICE)).isScreenOn()
tells if the screen is on. So, it gets true if the screen is on but the device is locked.
Instead,
inKeyguardRestrictedInputMode()
gets true just if the device is locked.