I wrote the Android lock screen control procedures, ideas generally are: the main interface has a screen lock button settings are controlled, then checked, the background will start a service, register a radio, listening screen_of behavior, if you listen to enter their Customizable interface locked, if not checked, you need to stop service. (Of course, need to set the value of a sharePreference exit on the storage time, if set, when the next time you start, you need to start the service), I checked on it, to enter into their own custom interface, but canceled check, At this point if you press the power button (lock screen button), should be the default interface into the system, but I did not enter, but is staying in the current interface, the interface seems to be the whole system does not, like, made me forget you shoes Good advice ah, Jia, because internships, less experienced, no way, ah, in this first blog friends Thank you friends!
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The key code is as follows (the main interface Activity)
package com.sds.android.ttpod.lockScreen;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class LockSetting extends Activity {
private final String LOCK_SCREEN_ON_OFF = "lock_screen_on_off";
private CheckBox mSetOnOff;
private boolean mIsLockScreenOn;
private SharedPreferences lockScreenSetting;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
/ / Set variables
SharedPreferenceslockScreenSetting = this.getSharedPreferences (LOCK_SCREEN_ON_OFF, 0);
Log.d ("sharePreference", lockScreenSetting.getBoolean ("isLockScreen", false) + "");
/ / Read value last saved
mIsLockScreenOn = lockScreenSetting.getBoolean ("isLockScreen", false);
/ / If True, start Service
if (mIsLockScreenOn) {
final PackageManager pm = getPackageManager ();
final ComponentName lockScreenService = new ComponentName (LockSetting.this, MyLockScreenService.class);
/ / Make the service component available
pm.setComponentEnabledSetting (lockScreenService, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
startService (new Intent (LockSetting.this, MyLockScreenService.class));
Log.d ("setting true", "must start service");
}
Value / / set the control to the last saved
mSetOnOff = (CheckBox) findViewById (R.id.set_onoff);
mSetOnOff.setChecked (mIsLockScreenOn);
When operating
/ / status changemSetOnOff.setOnCheckedChangeListener (new OnCheckedChangeListener () {
@ Override
public void onCheckedChanged (CompoundButton buttonView,
boolean isChecked) {
/ / Update the new sharePreference value
. lockScreenSetting.edit () putBoolean ("isLockScreen", isChecked) commit ();.
Log.d ("sharePreference", lockScreenSetting.getBoolean ("isLockScreen", false) + "");
if (buttonView.isChecked ()) {
mSetOnOff.setText ("Set ttpod LockScreen ON [Now is on].");
/ / Final PackageManager pm = getPackageManager ();
/ / Final ComponentName lockScreenService = new ComponentName (LockSetting.this, MyLockScreenService.class);
/ / / / Enable service component available
/ / Pm.setComponentEnabledSetting (lockScreenService, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
/ / Start the service monitor (screen lock control messages)
startService (new Intent (LockSetting.this, MyLockScreenService.class));
EnableSystemKeyguard (false);
} Else {
/ / Final PackageManager pm = getPackageManager ();
/ / Final ComponentName lockScreenService = new ComponentName (LockSetting.this, MyLockScreenService.class);
/ / / / Enable service component is not available
/ / Pm.setComponentEnabledSetting (lockScreenService, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
Service listens
/ / StopstopService (new Intent (LockSetting.this, MyLockScreenService.class));
mSetOnOff.setText ("Set ttpod LockScreen ON [Now is off].");
EnableSystemKeyguard (true);
Log.d ("test message", "StopService, the right choice is gointo the system lockScreen");
}
}
});
/ / EnableSystemKeyguard (false);
}
/ ** /
@ Override
protected void onStart () {
super.onStart ();
}
@ Override
protected void onStop () {
super.onStop ();
/ / Get the current value
set of exit controlsmIsLockScreenOn = mSetOnOff.isChecked ();
if (mIsLockScreenOn)
/ / Keep on disabling the system Keyguard
EnableSystemKeyguard (false);
else {
/ / Stop Service
stopService (new Intent (this, MyLockScreenService.class));
/ / Final PackageManager pm = getPackageManager ();
/ / Final ComponentName lockScreenService = new ComponentName (LockSetting.this, MyLockScreenService.class);
/ / / / Enable service component is not available
/ / Pm.setComponentEnabledSetting (lockScreenService, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
/ / Restore the original keyboard
EnableSystemKeyguard (true);
}
System.out.println ("the outInformation exits in LockSetting Actinvty's Method OnStop");
/ / Save settings when exiting
lockScreenSetting.edit () putBoolean ("isLockScreen", mIsLockScreenOn) commit ();..
}
private void EnableSystemKeyguard (boolean bEnable) {
/ / Declare a keyboard manager
KeyguardManager mKeyguardManager = null;
/ / Declare keypad lock
KeyguardLock mKeyguardLock = null;
/ / Get the keyboard system service object
mKeyguardManager = (KeyguardManager) getSystemService (Context.KEYGUARD_SERVICE);
/ / / / Initialize the keyboard lock, you can lock or unlock the keypad lock
mKeyguardLock = mKeyguardManager.newKeyguardLock ("");
if (bEnable)
/ / Unlock the keypad lock
mKeyguardLock.reenableKeyguard ();
else {
/ / Disable the display keypad lock
mKeyguardLock.disableKeyguard ();
}
}
}
Reply:
Here is the background service
package com.sds.android.ttpod.lockScreen;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class MyLockScreenService extends Service {
private final String ACT_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
@ Override
public IBinder onBind (Intent intent) {
Log.d ("", "*********** onBind MyLockScreenService");
return null;
}
@ Override
public void onCreate () {
super.onCreate ();
/ / Register Radio listeners
registerReceiver ();
}
public void onStart () {
/ / Register Radio listeners
registerReceiver ();
}
@ Override
public void onDestroy () {
super.onDestroy ();
unregisterReceiver (mScreenBCR);
Log.d ("", "destroy service, unregister Receiver"!);
}
public void registerReceiver () {
/ / Register Broadcast
Log.d ("", "*********** onCreate registerReceiver");
IntentFilter intentFilter = new IntentFilter (ACT_SCREEN_OFF);
registerReceiver (mScreenBCR, intentFilter);
}
/ / Define a broadcast receiver
private BroadcastReceiver mScreenBCR = new BroadcastReceiver () {
@ Override
public void onReceive (Context context, Intent intent) {
if (intent.getAction (). equals (ACT_SCREEN_OFF)) {
try {
Log.d ("", "our custom lockScreen action");
/ / Perform their own definitions LockScreen
Intent i = new Intent ();
i.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClass (context, LockView.class);
context.startActivity (i);
} Catch (Exception e) {
/ / Handle exceptions
Log.e ("", "*********** onReceive Error =" + e);
}
}
}
};
}
Reply:
Program lock, right? Open service time, once every second to get the first activity of the current activity stack package name, which is currently running program to determine whether the user checked. Yes, enter a custom interface, custom interface can be what you need to enter a password. The logic can be straightened out, do not understand why use system that locks the screen, the user experience of tolerance
Reply:

Reply:
Ha ha. Brother, you do not look good content, in fact, is a lock screen control software, then I checked, and can enter into their own custom interface, own their own customized interface by touching the slide to unlock, then uncheck the problem is, and then lock screen button, you can not enter into the lock screen system, why has this logic is because the user's own system you can not just lock screen shield, should be retained, or have ventured to use your software.
Reply:
My logic is very clear, and then checked to start listening radio service, if found to have lock screen radio, then enter your own custom lock screen. If you cancel after the check, press the lock screen button, the system will have to revert to the original default lock screen.
Reply:

Reply:
Your service inside the onCreate and onStar periodic functions which are registered with a radio receiver, is not repeated. In addition keyboard lock is closed there after being turned on, which is something you need to check the next. The best beat the log, look carefully log.
Reply:
Oh, thank you, service inside the onCreate and onStart periodic functions which are registered with a radio receiver, this is not repeated, onCreate function only takes effect when you first start, but onStart service in each start time will be execution, it does not affect the code on the keypad lock I have some not very clear, (I think before the keyboard lock, tried, but did not succeed, I am in the main interface Activity LockSetting one else onCheckedChanged events branch (the default is to enter the system lock screen, adding a word EnableSystemKeyguard (true) to open the keyboard lock) brothers, you help me explain this code chant (or look at my code so what's the problem):
/ / Declare a keyboard manager
KeyguardManager mKeyguardManager = null;
/ / Declare keypad lock
KeyguardLock mKeyguardLock = null;
/ / Get the keyboard system service object
mKeyguardManager = (KeyguardManager) getSystemService (Context.KEYGUARD_SERVICE);
/ / / / Initialize the keyboard lock, you can lock or unlock the keypad lock
mKeyguardLock = mKeyguardManager.newKeyguardLock ("");
if (bEnable)
mKeyguardLock.reenableKeyguard (); / / unlock the keypad lock (I'm not sure this explanation, you help me see, this particular is what does it mean, is not this sentence, you can enter the system on behalf of the lock screen)
else {
/ / Disable the display keypad lock
mKeyguardLock.disableKeyguard (); / / (there is this sentence yet)
}
}
Reply:
Hello, I research the lock screen not by much, but checked the online information summarized under:
1 on the lock screen requires the following permissions:
2 lock screen comes to synchronization problem, disableKeyguard and reenableKeyguard operations need to be synchronized, you need these two operations into a synchronized approach to operations.
If you will go to this address to download the project with svn lock screen, then carefully study: http://mylockforandroid.googlecode.com/svn, a good example of this matter, I hope useful to you ~
Reply:
Hello, looked under your post issued a long time, do not know what your problem resolved? I was doing when the lock screen appears and you almost question!
Reply:
Issue has been resolved!
Reply:
I was in the first third-party program to implement effective disableKeyguard, press the power button to resume the default of the double lock screen. .
No comments:
Post a Comment