Issues such as the title, I find a lot of code, in accordance with the test method on the surface to try to unlock the can, but the screen is not lit ah. I do not know the specific details of the code where the error, there is no one to give me a Demo, must be able to run up the right ah. Do not copy over the Internet, so no. Can be sent to my mailbox feixuedefeng@163.com<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
When do do reminders that time, the code is a service
Activity write a landlord can start the service, open the service with a thread, start only if the black under the effect of the state.
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;
public class ScreenService extends Service {
/ / Declare a keyboard manager
KeyguardManager mKeyguardManager = null;
/ / Declare keypad lock
private KeyguardLock mKeyguardLock = null;
/ / Declare Power Manager
private PowerManager pm;
private PowerManager.WakeLock wakeLock;
@ Override
public IBinder onBind (Intent arg0) {
return null;
}
@ Override
public void onCreate () {
/ / Get the service
powerpm = (PowerManager) getSystemService (Context.POWER_SERVICE);
/ / Get System Service
mKeyguardManager = (KeyguardManager) getSystemService (Context.KEYGUARD_SERVICE);
super.onCreate ();
}
@ Override
public void onStart (Intent intent, int startId) {
/ / Point shiny screen
wakeLock = pm.newWakeLock (PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wakeLock.acquire ();
Log.i ("Log:", "------> mKeyguardLock");
/ / Initialize the keyboard lock, you can lock or unlock the keypad lock
mKeyguardLock = mKeyguardManager.newKeyguardLock ("");
/ / Disable the display keypad lock
mKeyguardLock.disableKeyguard ();
}
@ Override
public void onDestroy () {
wakeLock.release ();
super.onDestroy ();
}
}
Remember the need to add
in AndroidManifest file<-! Unlock permissions ->
<-! Privileges bright screen ->
Reply:
Upstairs positive solution.
Reply:
Sorry ah, single wrong, throw a brick. Oh
I tried it, first let me start with startService found so used, you will find the screen has not completely black. So I think the use bindService, specifically how to use, I did not try. Second, although the screen lit up, but not as thoroughly brighten like normal operation, ah, this makes the screen light up just a little brighter, or very dark. Is that right? I use sdk9
Reply:
You stopService in Activity of stop method,
Then Service will destory the bright screen method to release mWakelock.release ();
This would not have been lit up,
As the brightness of the screen sdk did not say so in the end how bright,
public void acquire () / / This method is only to ensure that the screen will be awakened
Makes sure the device is on at the level you asked when you created the wake lock.
public void acquire (long timeout) / / parameter represents the wake time after time, it will automatically release the lock
Makes sure the device is on at the level you asked when you created the wake lock. The lock will be released after the given timeout.
Reply:
Learn
Reply:
huweilong1030, answered Awesome ah. Grateful, ha ha!
Reply:
Reply:
That light is not lit up, but then I looked to find API, which has a parameter can be lit. Oh
Reply:
Reply:
Learning ah, but see not quite understand, I want to achieve in the lock screen when long press answer key you can unlock you have any idea ah?
Reply:
What ya ..., this code is just to keep the screen always awake, in order to allow the successful completion of the operation will not be interrupted Bale lock screen. If you press the power button on the side of the phone, the screen is completely black out the system on sleep, I ask in this state is completely black, you use a service from one activity to wake about what powermanager try! ? ...
Reply:
Too fast hardware. . . .
Reply:

Reply:
Agree ~
Reply:
Recently used in the project, wrote articles under the record, you can look at. Android screen lit (lit) and lock and unlock the screen
Reply:
The landlord, api in in the end what parameters can brighten the screen completely, ah, ah
can give pointers
Reply:
newWakeLock in the flag
PowerManager.SCREEN_DIM_WAKE_LOCK replaced PowerManager.SCREEN_BRIGHT_WAKE_LOCK on the line
There is a PowerManager.ON_AFTER_RELEASE is relatively useful feature is the literal meaning
Reply:
Too much to force the second floor, the program is absolutely easy to use. Extremely grateful to you for sharing.
No comments:
Post a Comment