Calling an application with a lock screen

I want to launch the application immediately after unlocking the screen and during loading. How is this possible? What changes do I need to make?

+3


source to share


1 answer


First you need permission in your manifest:

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

      

Also, in your manifest, define your service and listen for the loading 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:enabled="true"
    android:exported="true"
    android:label="StartMyServiceAtBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

      

Next, you need to define a recipient who will receive the BOOT_COMPLETED action and start your service.

public class StartMyServiceAtBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            Intent serviceIntent = new Intent("com.myapp.MySystemService");
            context.startService(serviceIntent);
        }
    }
}

      

And now your service should start when your phone starts.

+2


source







All Articles