Add receiver to manifest file
<receiver android:name=".ScreenReceiver"> <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver>
Create a broadcast receiver that works to open the application when the phone is unlocked.
public class ScreenReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { System.out.println(intent.getAction()); if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { Intent intent1 = new Intent(context,MainActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent1); } }
I am sure this will work.
Naresh sharma
source share