,如果你想創建在主屏幕上您的應用程序,請參見以下鏈接
this和this
但如果你想你的代碼以前更加手機使用KeyguardLock和WakeLock loocked。以下是我所做的:
public class DismissLock extends Activity {
PowerManager pm;
WakeLock wl;
KeyguardManager km;
KeyguardLock kl;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.i("INFO", "onCreate() in DismissLock");
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
kl=km.newKeyguardLock("INFO");
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE, "INFO");
wl.acquire(); //wake up the screen
kl.disableKeyguard();// dismiss the keyguard
setContentView(R.layout.main);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
wl.release(); //when the activiy pauses, we should realse the wakelock
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
wl.acquire();//must call this!
}
}
當然,您仍然需要在清單文件中聲明權限。
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
////編輯
,如果你想加入兩項工作必須用本編輯代碼:
boolean fDialogMode = getIntent().hasExtra("dialog_mode");
if(! fDialogMode) {
super.setTheme(android.R.style.Theme_Dialog);
}
AlertDemo alert = new AlertDemo();
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
kl=km.newKeyguardLock("INFO");
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE, "INFO");
wl.acquire(); //wake up the screen
kl.disableKeyguard();// dismiss the keyguard
/** Opening the Alert Dialog Window */
alert.show(getSupportFragmentManager(), "AlertDemo");
,並在另一個包或接收器加下面的代碼:
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.example.openlock");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
閱讀http://stackoverflow.com/questions/7591670/pop-up-dialog-in-android-home-screen和http://stackoverflow.com/問題/ 2705162 /怎麼辦,他們-做它的對話框環比主屏 –
謝謝:)但是,當手機已經opened.Any當手機處於鎖定狀態,只顯示警告,這並不工作幫幫我? – user3008437
看到我的回答,它工作正常 –