Domanda

I'm programming an app that must stay on the screen of a tablet which is accessible by everyone.

This means that only people who know the passcode can access the tablet, while passing-by users can only use the app. However, I'm stuck on the home button. Is there any way to change it? Disable, control, anything?

È stato utile?

Soluzione

You can make your application as a Home screen launcher app using very similar activity code in your AndroidManifest. This way when user press the home button your app will be opened.

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:excludeFromRecents="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <!-- The following two intent-filters are the key to set homescreen -->
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>

Altri suggerimenti

It seems what you need to do is make a launcher to replace the default home screen. Otherwise there is no way to change the home key behavior.

To make a launcher, check this How to make a launcher

I have tried this on Android ICS and it works:

<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />

When i press the home button with this set in my Android manifest the activity automatically starts.(The first time it asks if i want to go to Xperia Home or Start my Application, i can also make that permanent)

Though i do have a question, I want to be able to open my application when i hold down the home button, how could i do this?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top