How do you create your Activity that will be displayed when the shield is activated?



  • Good day! Please indicate how this mechanism is being implemented, like on the crypto? We need to get the user on the switch button when the screen is pressurized, my activity immediately after the screen is activated. I tried to use it. BroadcastReceiver and traced the event Intent.ACTION_USER_PRESENT♪ But this event comes after the screen is unlocked. I should be grateful if you could answer my question. With your best wishes, Sergei!
    введите сюда описание изображения



  • First part of a solved problem. We're building a class inherited from BroadcastReceiver:

    public class LockscreenReceiver extends BroadcastReceiver {
    

    public LockscreenReceiver() {

    }

    public static final String TAG = "myPlayer";

    @Override
    public void onReceive(Context context, Intent intent) {
    try {
    if ( intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
    Log.d(TAG, "LockscreenReceiver");
    Intent mIntent = new Intent(context, LockScreenActivity.class);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(mIntent);
    }
    } catch (Exception e) {
    Log.d(TAG, "Error BroadcastReceiver", e);
    }
    }
    }

    We record our reciver either active or service. Where we want to dynamically run the listener. In my case, it's activity. And we'll hand over BroadcastReceiver to the filtration filter: android.intent.action. SCREEN_ON:

    private LockscreenReceiver lockscreenReceiver = new LockscreenReceiver();
    @Override
    protected void onStop() {
    super.onStop();
    this.registerReceiver(lockscreenReceiver, new IntentFilter("android.intent.action.SCREEN_ON"));
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2