0

Possible Duplicate:
android lock screen source code

I´ve created an app, that contains 2 activities. One is to setAPassword and the other is to realize the login. How can i place this App as LockScreen in Android? It should permanentely run.

Community
  • 1
  • 1
user1338278
  • 11
  • 1
  • 1
  • There is a similar question here http://stackoverflow.com/questions/2140964/android-lock-screen-source-code – sherif Apr 17 '12 at 09:56

1 Answers1

2

Just a guess of mine

  1. disable back key
  2. disable home key
  3. No menu
  4. Listen Boot Start of device and launch your screen again
  5. only on successful login call finish()

for task 1,2,3 search stackoverflow . They are there for sure..

Also there are option in android for making your own home screen/ launcher screen. for e.g go_launcher app in android

for disabling home key try this full activity code is

package com.lockscreen;

import android.app.Activity;
import android.app.KeyguardManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;

public class LockScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock lock = keyguardManager
            .newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();

}

@Override
public void onBackPressed() {

}

@Override
public void onAttachedToWindow() {
    // TODO Auto-generated method stub
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    menu.add("Exit");
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getTitle().equals("Exit")) {
        finish();
        System.runFinalizersOnExit(true);
        System.exit(0);
    }
    return super.onOptionsItemSelected(item);
}

}

manifest needs permission

<uses-permission
    android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
Rohit Sharma
  • 13,787
  • 8
  • 57
  • 72