Calling an application with a lock screen
1 answer
-
To start the app when the screen is locked, you need to register a BroadcastReceiver for the Intent.ACTION_SCREEN_OFF for details see example http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents /
-
To launch the application at boot time you need a broadcast receiver that listens for the BOOT_COMPLETED action, please refer to How to start the application on startup?
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 to share