In my application I am using google account login to get logged into the application which is authenticated by our server side code after successful login and returns a control to our website custom url once done.
The url I am getting on successfull login is:
07-17 13:45:07.123: E/start(7208): https://www.mywebsite.com/auth/google/callback?code=4/tCw3uOWulXr0RO1ZG0C1hanEWNDc.IgNbwOdJ7uEcXE-sT2ZLcbSfjWjXfwI
I am able to see the json object on the webview it may be echo onto it.Making a guess as not a web developer.Attaching screen shot.
Server is responding separately according to my user agent explicitly declared for my app so that our custom server would respond accordingly for website and our app:
WebView login=(WebView)findViewById(R.id.loginWebview);
login.getSettings().setUserAgentString("user_agent_app");
Have tried for the last url mention above as a response from server but it is returning null though I can see the result in the webview.
public static String getResponse(String url){
String downloadedData = null;
Log.e("getResponse", url);
try {
URL downloadURL = new URL(url);
InputStream inputStream = (InputStream) downloadURL.getContent();
if (null != inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[512];
int readCounter = inputStream.read(buffer);
while (readCounter != -1) {
byteArrayOutputStream.write(buffer, 0, readCounter);
readCounter = inputStream.read(buffer);
}
downloadedData = new String(
byteArrayOutputStream.toByteArray());
/*if (null != downloadedData && !"".equals(downloadedData)) {
downloadedJson = new JSONObject(downloadedData);
}*/
}else{
Log.e("getResponse", "Response is null");
}
} catch (Exception e) {
e.printStackTrace();
}
return downloadedData;
}
It would be appreciable if some one can assist me how to retrieve the json object.