I am looking to insert userdata to database by calling URL link to webservice on server: ex: this is the link:
http://mydomain.com/AndroidWebService.asmx/nInsertInfo?id=12&lat=23.2222&log=12322
So I want to call this url in hidden mode.
I am looking to insert userdata to database by calling URL link to webservice on server: ex: this is the link:
http://mydomain.com/AndroidWebService.asmx/nInsertInfo?id=12&lat=23.2222&log=12322
So I want to call this url in hidden mode.
Use android android AsyncTask to post data. It work in android background when application is open. AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
Thanks.
Thanks all for your valuable solutions.
i have did it by creating WebView
WebView myWebView = (WebView) findViewById(R.id.view1);
myWebView.loadUrl(urll);
then i can manage my WebView as i want: hide it, alignment as error or result returns.
Maybe this example will help you :
public class URLConnectionTask <Result> extends AsyncTask<URL, Void, InputStream> {
@Override
protected InputStream doInBackground(URL... params) {
InputStream is;
HttpUriRequest request;
URI uri;
HttpResponse response;
if (params.length == 0)
return null;
is = null;CredentialsProvider credProvider = new BasicCredentialsProvider();
if (userName != null && userName.length() > 0 && password != null && password.length() > 0)
credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(userName, password));
//
DefaultHttpClient http = new DefaultHttpClient();
http.setCredentialsProvider(credProvider);
//
uri = URI.create(params[0].toString());
if (isPost)
request = new HttpPost(uri);
else
request = new HttpGet(uri);
try {
response = http.execute(request);
is = response.getEntity().getContent();
//Log.d(TAG, "doInBackground() response: "+EntityUtils.toString(response.getEntity()));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (processingHandler != null && is != null)
processingResult = processingHandler.processResponse(is);// processingHandler is an instance which implements ProcessingHandler interface (ex. VizMarket). processResponse() is implemented on this class.
return is;
}
@Override
protected void onPostExecute (InputStream result) {
input = result;
if (result == null)
return;
//instruction for inserting data on db ....
try {
result.close();
} catch (IOException e) {
}
}
}
U have to use a thread to fetch data from server and insert into to DB or in android you can use AsyncTask.
You can have a search :ClickableSpan And put your insert code into the OnClick body~ Just like:
String yourTextStr;
SpannableString sp = new SpannableString(yourTextStr);
int start;//the start of your url in the text;
int end ;//the end of your url in the text;
sp.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
//Your Insert Code
}
}, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);