如何禁用Android的主页按钮? [英] how to disable home button in android?
问题描述
我想禁用的Android设备主页按钮
时,我的应用程序运行。
我曾尝试以下code,但它din't帮助:
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
如果((钥匙code == KeyEvent.KEY code_HOME)){
Toast.makeText(这一点,你pressed home键!,
Toast.LENGTH_LONG).show();
返回false;
}
返回super.onKeyDown(键code,事件);
}
@覆盖
保护无效onNewIntent(意向意图){
super.onNewIntent(意向);
如果(Intent.ACTION_MAIN.equals(intent.getAction())){
Log.i(MyLauncher,onNewIntent:Home键);
}
}
我觉得这可以在另一种风格,如果适合您的要求来完成。通过创建活动作为家庭活动。如果您希望禁用的主页按钮,并显示您的自定义应用程序活动作为启动时,home键是pssed $ P $。就在清单对于您希望您的启动程序活动添加这些行。
<活动
机器人:名称=com.example.TempActivity
机器人:clearTaskOnLaunch =真
机器人:excludeFromRecents =真
机器人:launchMode =singleTask
机器人:screenOrientation =风景
机器人:stateNotNeeded =真正的>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.HOME/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
添加和运行应用程序之后。如果用户presses home键,机器人会问你希望你的家而发射器。然后,你需要选择你的应用程序启动器总是不只有一次。
如果你想完全禁用用户,使他不能移动到其他屏幕,然后设置主题,以全屏NoTitlebar。
如果你喜欢的答案。请不要忘记评分答案。谢谢
i want to disable android device home button
when my app runs.
i have tried following code but it din't help :
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
Toast.makeText(this, "You pressed the home button!",
Toast.LENGTH_LONG).show();
return false;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Log.i("MyLauncher", "onNewIntent: HOME Key");
}
}
I think this can be done in another style if suits your requirement. By creating your activity as home activity. If you want to disable home button and show your custom application activity as launcher when home button is pressed. Just add these lines in manifest for that activity for which you want your launcher.
<activity
android:name="com.example.TempActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:stateNotNeeded="true" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
After adding and run your application. if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.
if you want fully disable the user, so that he cant move to another screen then set theme to fullscreen with NoTitlebar.
if you like the answer. please dont forget to rate the answer. Thanks
这篇关于如何禁用Android的主页按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!