Unable to open URL after screen lock

My code to open url in browser

private void openBrowserUrl(String url) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    System.out.println("============Url==================" + url);

    i.setData(Uri.parse(url));
    startActivity(i);
    unlock(UNLOCK_TO_HOME);
}

      

The above works fine when there is no pattern lock.

But when I tried to open the browser after blocking the pattern, the URL value remains empty.

I have a custom lock screen in my application. When the phone is locked, after that I tried to unlock the phone, while the custom lock window is opened by my app. and in this I wrote this code. I got url value and goes to browser successfully.

But, I tried with the above process with interrupt blocking (Android default blocking system)

then the flow

custom lock screen -> open url code (got url value) -> default pattern lock -> browser without url value.

In the above thread, when the pattern lock exists, the browser cannot get the url that I passed.

+3


source to share


1 answer


This issue occurs when api> 21. There have been some changes in KEYGUARD and after you unlock the screen there is some kind of delay or something that makes the intent not react, buying with flags it should delay intents and force its working the code here should fix the problem.



       getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("your url"));
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getActivity().startActivity(i);

      

0


source







All Articles