Android Display own lock instead of default when screen on/off

无人久伴 提交于 2019-12-04 19:08:26

I give my own answers : use follwing method in my BootReciever class :

 `enter code here`


           @Override
       public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
           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 menifest file use follwing :

enter code here : use : <action android:name="android.intent.action.USER_PRESENT" />
        <receiver
        android:name=".BootReciever"
        android:enabled="true"
        android:exported="false" >
        <intent-filter android:priority="1" >
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!