1

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

Sthe
  • 2,575
  • 2
  • 31
  • 48

4 Answers4

4

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!

EvZ
  • 11,889
  • 4
  • 38
  • 76
  • +1 This is in fact an interesting solution too, though it requires that this launcher is set as default. Depending on the home screen features that have to be implemented it might be a bit complex. But in return you gain a lot of control. – Trinimon May 09 '13 at 12:19
  • I tried this solution, it looks like its the right approach, but I couldn't use it due to my lack of experience in Android. I was able to create a launcher, but the problem is that every time I try to open another app, it gives me a list of available launcher apps, which defeats the purpose because a kid can choose the default one, thereby guaranteeing herself access to any other app. I might be missing something though. I don't know. – Sthe May 15 '13 at 15:18
3

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.

Jibran Khan
  • 3,236
  • 4
  • 37
  • 50
  • That will not block the user from accessing the home screen or any other app. this approach will insure they your app has starts on the boot, also what's up with the separate package ? – Mr.Me May 09 '13 at 12:08
  • separate package means to create the class outside of activity, else it will not route the receiver class from manifest. This approach worked for me, may be there will be other ways. – Jibran Khan May 09 '13 at 12:11
  • java packages are not the same as java compilation units (File), you need to have your Broadcast Receiver to be a top level class in a cu (java source file). http://en.wikipedia.org/wiki/Java_package . http://blog.ajduke.in/2012/09/23/java-compilation-unit/ – Mr.Me May 09 '13 at 12:19
  • Thanks. This addressed the first part of my question. I'm still struggling with how to lock access to other applications though. – Sthe May 15 '13 at 15:14
  • You want to avoid your application to be closed. – Jibran Khan May 16 '13 at 04:49
2

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!

Community
  • 1
  • 1
Trinimon
  • 13,839
  • 9
  • 44
  • 60
1

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 ...).
Community
  • 1
  • 1
Mr.Me
  • 9,192
  • 5
  • 39
  • 51