Sthe
Sthe

Reputation: 2695

Android - Autostart app and restrict access to other apps

I'm fairly new in Android development and I have an app that I'm working on for kids. I would like the app to start itself when the device starts up. When the app is running, I want it to prevent access to any other screens. Disable home buttons, prevent access to browser, settings etc.

Is this possible to do? I stumbled across this link http://www.androidsnippets.com/autostart-an-application-at-bootup, but a few people think it's not a good approach to allow activities to start automatically.

Thank you :-)

Upvotes: 1

Views: 7279

Answers (4)

Trinimon
Trinimon

Reputation: 13957

Regarding your question:

  1. "I would like the app to start itself when the device starts up."

    You can implement a BroadcastReceiver for catching the RECEIVE_BOOT_COMPLETED event. See this post.

  2. "When the app is running, I want it to prevent access to any other screens."

    You could restart your activity whenever it got destroyed or paused. You could check this in a background Service. Check this post for more.

  3. "Disable home buttons"

    Simply not possible. You have to rely on the result of 2. here.

  4. "prevent access to browser, settings etc."

    Similar to 3. - you can't really avoid this. However, you can check if your app is on top and restart it, if not.

Hope this helps ... Cheers!

Upvotes: 3

EvZ
EvZ

Reputation: 12169

Sounds like you need your own launcher, because only launcher can prevent access to unnecessary screens and Home button will be "blocked" with your launcher.
It will also solve the "start-up" problem.

All you need to do is to declare Activity in your AndroidManifest like this:

<activity
android:name="your.package.ActivityName
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

Activate your creativity, and build launcher for your needs.
Good luck!

Upvotes: 4

Mr.Me
Mr.Me

Reputation: 9276

You can build a Home App that will be the device interface with the user, by doing so you can manage the user experience. take a look here : SO Question

But building a Launcher/Home app includes a lot of responsibilities. you will be responsible for all user access:

  • settings
  • Telephony
  • Other apps
  • Basic smartphone apps (Mail , calendar ...).

Upvotes: 1

Jibran Khan
Jibran Khan

Reputation: 3256

This is to set the app as the startup application in your device Create a Class extends BroadCast Reciever

public class BootUpReciever extends BroadcastReceiver
{

@Override
public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, ServerPreferenceActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
}
}

Add permissions to manifest file to excess bootup receiver

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

Register your receiver which extended the Broadcast receiver in manifest.xml

<receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
    <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

Note: Create the receiver class in a separate package in the src folder to acheive the working implementation.

Upvotes: 3

Related Questions