Good day! Please tell me how this mechanism is implemented, as in the screenshot? It is necessary that when the user presses the off button, immediately after the screen is turned on, my activity is displayed. I tried to use BroadcastReceiver and was tracking the Intent.ACTION_USER_PRESENT event. But this event comes after the screen is unlocked. I would appreciate an answer to my question! Best wishes, Sergey!
- try ACTION_SCREEN_ON - Ziens
- Ziens, you were absolutely right! Thank you so much for your help. I can only say that in order to track this event, we need to register the broadcast receiver with an IntentFilter ("android.intent.action.SCREEN_ON") not in the manifesto but in the Activity or in the Service. - Sergey
- @ Sergey, describe, pzh-ta, the decision in the answer) - YuriySPb ♦
- Good day! I dealt with the first part of the question. To monitor the event the inclusion of the screen is obtained. To do this, register the class inherited from the BroadcastReceiver in the Activity or in the Service with the IntentFilter: android.intent.action.SCREEN_ON Now the question is how to do so that when this event occurs, when I open my activity, it has priority over the blocker activity? There is an option to use the style of the dialog box for an activity, then it should appear above all activities and fragments. Perhaps there are some other options? - Sergey
|
1 answer
The first part of the solved problem. Create 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 register our receiver either in activity or in service. In the place from where we want to dynamically control the listener. In my case it is an activity. And pass the BroadcastReceiver filter of intent: 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")); } - The Q & A service policy is such that there can be only one problem in one question. To solve another problem, create a new question. - pavlofff
|