android unlock screen intent?

前端 未结 3 1216
傲寒
傲寒 2020-12-03 15:25

Is there an intent that is fired when a user unlocks their screen? I want my app to adjust the brightness when the screen turns on, but the problem im running into is that

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 15:58

    Add the receiver in menifest file

    
                
                    
                
            
    

    Create a broadcast receiver which works to open app when 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'm sure it will work.

提交回复
热议问题