Search code examples
androidlockingbroadcastreceiverlockscreen

Android lock screen : activity started first when mobile on


I develop one apps mobile number lock, i want whenever mobile on,or restart or switch on ,or on from the top/left/right button placed on mobile in short whenever mobile screen on my lock activity call, i have no idea to how to call activity at time of mobile on please any one give some related example to start activity at first when mobile on. so my lock dispay to user and then enter number password and lock open ...thanks in advance..


Solution

  • Following is working for me :

    enter code here :
        public class BootReciever extends BroadcastReceiver {
    
     @Override
     public void onReceive(Context context, Intent intent) {
         if (intent.getAction() != null) {
               if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                Intent s = new  Intent(context,ViewPagerMainActivity.class);
                s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(s);
                }
           }
        }
    }
    
     and in menifist file add follwing:
    
    enter code here :
    <receiver android:name=".BootReciever">
            <intent-filter android:enabled="true" android:exported="true">
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
    </receiver>