English 中文(简体)
如何再生 当家纽顿受到压力时,关键卫士?
原标题:Android How to reenableKeyguard when home button is pressed?
  • 时间:2011-11-22 19:08:06
  •  标签:
  • android

For several days i am trying to find a solution to this question, there are a lot of posts already on google and on this website, and from all of this is seems that it is impossible to override home button.

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

For certain this it won t work.

不管怎样,在什么地方可以看一看工作,让你在压力下引发某种事情,似乎有一部分工作要做。

protected void onUserLeaveHint() {
     super.onUserLeaveHint();
     Log.i("LOG", "onUserLeaveHint");
}

但是,我想要做的是可再生的凯保拉(我知道,为了让锁的屏幕首先能够脱掉)偏离这种方法,但出于某种原因,它赢得了拖网。 因此,这是我的法典。

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_lock); 
    }

    public void onStart() {
        super.onStart();
        Globals.km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
        Globals.kl = Globals.km.newKeyguardLock("My_App");
        Globals.kl.disableKeyguard();
        Log.i("LOG", "OnStart");
    }

    public void onResume() {
        super.onResume();
        Log.i("LOG", "OnResume");
    }

    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        Log.i("LOG", "onUserLeaveHint");
        Globals.kl.reenableKeyguard();
    }

    public void onPause() {
        super.onPause();
        Log.i("LOG", "OnPause");
    }

    protected void onStop() {
        super.onStop();
        Log.i("LOG", "OnStop");
    }

Reenable works only when the activity start, so if i put it inside of onPause() the lock screen will appear. But when i press home it doesn t work.

谁能告诉我,我究竟是做错了吗? Thanx。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签