我構建了自定義鎖定屏幕應用程序,該應用程序使用廣播接收器和服務來偵聽用戶何時打開或關閉屏幕,並從那裏啓動我的活動。該活動應該完全取代鎖定屏幕。爲了做到這一點,我的應用程序應該禁用Android股票鎖,以便我的應用程序可以作爲新的鎖定屏幕。自定義鎖定屏幕應用程序中的android鎖定問題
取而代之的是,一旦應用程序第一次安裝,服務首次啓動應用程序似乎正在工作。當用戶首次關閉手機的屏幕時,他們將會看到我的應用程序在頂部運行,並且能夠使用我的應用程序解鎖他們的手機。但是如果用戶按下home按鈕,那麼一旦進入android操作系統,他們下一次關閉屏幕並將其重新打開,而不是被帶回到我的應用程序,它們被帶到股票解鎖屏幕,我的應用程序在其下面打開,當它應該是最高的。
這裏是我的代碼:
我的服務:
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.d("MyService","Service STARTED");
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
final BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
}
}
我的廣播接收器:
public class ScreenReceiver extends BroadcastReceiver {
public static ArrayList<String> runningApplications = new ArrayList<String>();
private Context ctext;
public static boolean screenIsLocked;
public static KeyguardManager keyguardManager;
public static KeyguardLock lock;
@Override
public void onReceive(final Context context, final Intent intent) {
ctext = context;
keyguardManager = (KeyguardManager)ctext.getSystemService(Activity.KEYGUARD_SERVICE);
lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE);
lock.disableKeyguard();
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenIsLocked = true;
Log.d("ScreenReceiver", "False");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenIsLocked = false;
Log.d("ScreenReceiver", "True");
Intent intenti = new Intent();
intenti.setClass(context, starterActivity.class);
intenti.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intenti.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intenti);
}
}
我所啓動的活動是隻用一個解鎖按鈕調用finish();
基本清空當按下時。
這可能是因爲該應用程序被設置....不此問題發生連續?? – jaisonDavis 2012-07-21 15:27:19