Am trying get user session userid from android webview, but using the below code my app will forcefully stop working, without any error while building the apk. Please i am still trying to complete my first webview app am still very new in android
public String getCookie(String siteName,String CookieName){
String CookieValue = null;
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(siteName);
String[] temp=cookies.split(";");
for (String ar1 : temp ){
if(ar1.contains(CookieName)){
String[] temp1=ar1.split("=");
CookieValue = temp1[1];
break;
}
}
return CookieValue;
}
Reference to above code https://stackoverflow.com/a/20241926/8778864
public void onPageFinished(WebView view, String url) {
String cookies = CookieManager.getInstance().getCookie(url);
showAlert(FoodShopMainActivity.this, "Cookies", "cookies string:" + cookies);
}
The above code will output PHPSESSID=g675654hghghf7ghgyty
, but what is only the session userID.
public void onPageFinished(WebView view, String url) {
/*String userCookie = getCookie("http://www.example.com","online_users");
showAlert(FoodShopMainActivity.this, "Cookies", "cookies string:" + userCookie);*/
}
The above code will show app has stopped working
once lunched