Tuesday, 27 April 2021

How to check facebook login status in Webview android?

I am developing an android application where i have redirected to https://m.facebook.com/ inside a web-view. I want to check the login status is success or failed and display view according to login status. But i am unable to find any solution for this.

I have tried checking URLs in onLoadResource and found some URLs that we get on successful login and logout. But its still not enough as Facebook login can be done via different methods (i.e by number, by email, by already saved account etc).

To check Logout:

fun isFacebookLoggedOut(url: String?): Boolean {
    return url?.startsWith("https://m.facebook.com/?stype=lo&jlou")!!
}

To check Login:

fun isFacebookLoggedIn(url: String?): Boolean {
    if (url.equals("https://m.facebook.com/login/save-device/?login_source=login#_=_") || url.equals(
            "https://m.facebook.com/login/save-device/cancel/?flow=interstitial_nux_retry&nux_source=regular_login"
        ) || url?.contains("https://m.facebook.com/login/device-based/validate-pin/?refid=")!!
    ) {
        return true
    } else {
        if (url.startsWith("https://m.facebook.com/login/device-based/login/async/?") || url.startsWith(
                "https://m.facebook.com/login/account_recovery/name_search/?flow=initiate_view&ls=initiate_view"
            )
        ) {
            return true
        } else {
            return false
        }

    }

}

This works in some cases and on some devices but there are scenarios when user log in with contact number, or saved account which goes through different phases like entering credentials then verifying any code if browser is new and so on.

Is there any method or proper way to track login status thats perfect for each scenario and each device?

Can somebody please help me out with this. Any help will be appreciated



from How to check facebook login status in Webview android?

No comments:

Post a Comment