Android 屏蔽HOME键
package shoujizhengren.co.cc;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.Toast;
public class Suiping extends Activity {
@Override
protected void onCreate(
Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public boolean onKeyDown(
int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
Intent i = new Intent(
Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
Toast.makeText(
Suiping.this,
"弹出对话框", 1000)
.show();
Intent intent = new Intent(
Suiping.this,
ShoujizhengrenActivity.class);
startActivity(intent);
finish();
return true;
}
else {
return super.onKeyDown(
keyCode, event);
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
}
//屏蔽HOME键
public void onAttachedToWindow() {
this.getWindow()
.setType(
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
}
-------------------androidmanifest.xml
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
作者:gongzibai
补充:移动开发 , Android ,