Search code examples
androidgoogle-glassandroid-launcherautostartrooted-device

Google Glass - Autostart Application on Boot


I just received a new google-glass from a company which wants it to support their employees while picking and packing goods in their warehouse. For this reason they need a Server Client application which really isn't the problem.

I never did something with the Glass before and i want to know if it is possible to run a custom Application on boot and to jail the user into it.

Yesterday i rooted the device which gives me full access but i don't know how to go on.

Thank you!


Solution

  • Yes, it is possible.

    As you have rooted the device, so you can create system app that can be recognised by the reboot event. Rest of the steps are totally similar to android mobile.

    How to do it:

    If you need to know the steps you can search on the web or you can try the following:

    First, you need the permission in your AndroidManifest.xml:

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

    Also, in yourAndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:

    <service android:name=".MyService" android:label="My Service">
        <intent-filter>
            <action android:name="com.myapp.MyService" />
        </intent-filter>
    </service>
    
    <receiver
        android:name=".receiver.StartMyServiceAtBootReceiver"
        android:label="StartMyServiceAtBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    

    Then you need to define the receiver that will get the BOOT_COMPLETED action and start your service.

    public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                Intent serviceIntent = new Intent(context, MySystemService.class);
                context.startService(serviceIntent);
            }
        }
    }
    

    And now your service should be running when the phone starts up.