锁定触控按键
1 在KeyEvent文件 中自定义键值
KeyEvent.KEYCODE_KEYLOCK
2 PhoneWindowManager 在方法public int interceptKeyTq()中加入
if(event.keycode == KeyEvent.KEYCODE_KEYLOCK && event.value != 0 ){
long when = System.currentTimeMillis();
if(!mTouchKeyLock){
mTouchKeyLock = true;
Context context = mContext;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager =(NotificationManager)mContext.getSystemService(ns);
IntentFilter filter = new IntentFilter();
filter.addAction(LOCK_ACTION);
mContext.registerReceiver(mBroadcastReceiver,filter);
int icon = com.android.internal.R.drawable.stat_key_locked;
CharSequence tickerText = mContext.getResources().getString(com.android.internal.R.string.label_key_locked);
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;
CharSequence contentTitle = mContext.getResources().getString(com.android.internal.R.string.label_key_locked_name);
CharSequence contentText = mContext.getResources().getString(com.android.internal.R.string.label_key_unlocked);
Intent intent = new Intent();
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(LOCK_ACTION);
PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(KEY_LOCKED_ID, notification);
result &= ~ACTION_PASS_TO_USER;
return result;
} else {
mTouchKeyLock = false;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager =(NotificationManager)mContext.getSystemService(ns);
mNotificationManager.cancel(KEY_LOCKED_ID);
result &= ~ACTION_PASS_TO_USER;
return result;
}
}
if(mTouchKeyLock){
if(event.keycode == KeyEvent.KEYCODE_MENU || event.keycode ==KeyEvent.KEYCODE_BACK
|| event.keycode ==KeyEvent.KEYCODE_SEARCH || event.keycode ==KeyEvent.KEYCODE_HOME){
result &= ~ACTION_PASS_TO_USER;
return result;
}
}