I am a beginner in Java and PHP.
I made a client Java app that uses webView to Pass a string to php client page which will insert this string to the DB.
my question is, how can I return a false value to the java client app in case the PHP failed to insert the string to the DB using webView.
the php code will be something like this:
if(Insertion suceed)
{return true;}
else {return false;}
but I dont know how to make it in the Java side.
P.S: I need the return value to display an alert to the java user to restart the app.
解决方案
You may try to communicate from php to java using get/post request. Communication the other way can be done by viewing xml or json response. Json is quite nice to answer and supported by php (php object may be parsed into json using json_encode()/json_decode() Java also supports json communication (see http://www.json.org/java/ ). Json allows sending null.
if all your php outputs/writes is the status of your insertion than code may look like
if(Insertion suceed){
echo "true";
}else {
echo "false:;
}
in java you need to capture the content of your Web view. i found simmilar problem and possible solution here
How do I get the web page contents from a WebView?. if it also outputs other data/web content than you just need to "hide" your status output somewhere and cut it out from output source string in java
now if you have your content in String value just use library located here:
http://code.google.com/p/json-simple/
your java code stould look like this (in my case "response" is the string with content):
String response = "false";
JSONParser parser = new JSONParser();
Boolean result = (Boolean)parser.parse(response);
i hope you understood