disable all home button and task bar features on Nexus 7

最后都变了- 提交于 2019-12-17 19:32:39

问题


I am building an app that will form part of an exhibition. It will be displayed on a Nexus 7 which will be securely mounted. The app has touchscreen functionality and will display interactive content.

I need to be able to disable as many features as possible whilst on display as I do not want the public to be able to get to anything other than the app.

The main thing I am struggling with is the back/home/recent app list button. I have found some examples of disabling home button (child lock Android - Is It possible to disable the click of home button ) but ideally I need the buttons to be invisible, so to turn off the 'glow' (black would be fine).

Is the bottom section on a Nexus 7 protected in some way, is there another version of Android that would allow me to do this? The Nexus device will only be used for displaying this app, no other functionality is needed.

Any suggestions would be great and very much appreciated.


回答1:


Your best solution without creating your own custom Android rom to remove the bottom buttons, will be to make the app full screen, override the back button, and make your app a launcher in order to override the home button.

AFAIK, there is no way of overriding the recent apps button.

Edit: One other option would to have a fullscreen app and then use a mount that will cover the buttons. (Thanks to MaciejGórski for the idea).

To make your app full screen, put the following in your activity's onCreate():

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Or you can make the app full screen from within the manifest as well, thanks to @Niels:

<application android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">

To override the back button, add this method:

@Override
public void onBackPressed() {
    return;
}

Now the home button is trickier, add the following to your manifest:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

and this to your manifest under the <activity>:

<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>

and this to your manifest under the <application>, make sure that the <receiver name> is the full package name path you define:

<receiver android:name="com.example.BootCompleteReceiver">
   <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />
   </intent-filter>
</receiver>

And lastly, create a java class file called BootCompleteReceiver, and use this code:

public class BootCompleteReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent startActivityIntent = new Intent(context, YourActivityName.class);
    startActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(parentActivityIntent);
  }
}

To later disable your app as a home screen launcher, press the recent app button, swipe down from the right side, tap settings, go to apps, then tap the upper right three dots (vertically aligned), press "Reset app preferences", and then finally press "Reset apps".

I think that should just about cover it all.

EDIT 2 I just realized/tested and you do NOT necessarily need the BOOT_COMPLETED intent if you make your application a launcher. This means that the <uses-permission>, <receiver>, and BootComplete.java are not needed. You can just use the <intent-filter> that includes the MAIN, HOME, and DEFAULT attributes.

EDIT 3 More/different information available here: Home Launcher issue with Fragments after reboot




回答2:


Further to the above, which all worked great, and to make sure a comprehensive answer is out there.....

AFAIK, there is no way of overriding the recent apps button.

I got around this by change onPause app behavior to start an alarmmanager. There may be a more elegant solution, but this works.

First, create repeating alarmmanager setupAlarm(seconds)( full details here and here, note I used repeating alarm rather than one off, think both will work though) that starts your activity

then change onPause to set a 2 second alarm, so whenever someone selects the recent apps button on the nav bar, a 2 second 'alarm' to start mainActivity is set.

@Override
public void onPause() {
    setupAlarm(2);
    finish(); //optional
    super.onPause();

}

So with this and the above, any attempt to use the navigation buttons or restart the app results in app starting. So until I get round to investigating the 'kiosk' style roms this is a very good compromise.




回答3:


I may be a bit late.

But i've found the, in my opinion, best solution for the Recent Apps Button Problem:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (&& !hasFocus) {
        // Close every kind of system dialog
        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);

        // send task back to front
        ActivityManager activityManager =
                (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
        activityManager.moveTaskToFront(getTaskId(), 0);
    }
}

The "send task back to front" part will prevent the pull down of the Notification bar by simply sending it back up instantly and will close the Recent Apps View. The other one is to close the "Shutdown/Restart" View when he tries to shut down his phone.

Now Excuse my English and have a nice Day.

Greetings Jimmy



来源:https://stackoverflow.com/questions/16657300/disable-all-home-button-and-task-bar-features-on-nexus-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!