Hi,
Like I said before I am new to Android and I don’t hide it but I’ve started to like it so far. And now I’d like to show you an application which enables sending data to the servers remotely. Before I give you the code, just look at the screens how it looks.
But if you don’t care how it works just download the application from here:
- Source code: https://github.com/strife/AndroidSendToServer
- Package for android: https://github.com/strife/AndroidSendToServer/blob/master/bin/SendToServer.apk (non authorized)
It should be compatibile with 2.3.3 API.
Preview:

Here you can easly send your data to server, just like that. But first of all you have to change settings by clicking on proper link.
How it works?
There is too many files to show, for that reason I decided to explain only few features.
How to make a progress bar?
It’s simple, in your Activity class you’ve got to create a class which will extends of AsyncTask it should look like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
... private class postData extends AsyncTask<String, Void, String> { private final ProgressDialog dialog = ProgressDialog.show(sendToServerActivity, "", "Saving data to server. Please wait...", true); @Override protected String doInBackground(String... params) { // perform long running operation operation SharedPreferences settings = context.getSharedPreferences(PREFS_FILE, 0); String server = settings.getString("server", ""); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(server); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("android", editText1.getText().toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); try { httpclient.execute(httppost); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // Execute HTTP Post Request // ResponseHandler<String> responseHandler=new BasicResponseHandler(); // String responseBody = httpclient.execute(httppost, responseHandler); // if (Boolean.parseBoolean(responseBody)) { // dialog.cancel(); // } } catch (IOException e) { // TODO Auto-generated catch block Log.i("HTTP Failed", e.toString()); } return null; } ... |
And then if you’ve got already that construction you can simply run it. In my example it looks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public void sendItNow(Button button1) { button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub // check if every boolean isValidate = validate(editText1.getText()); if (isValidate) { // send to server and open progress dialog box new postData().execute(); // most important line } } }); } |
As you see I execute this class using .execute method.
PHP Script which saves data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php if (isset($_POST['android'])) { file_put_contents("android.txt", $_POST['android']); echo 1; } ?> |
Note: File android.txt has to have proper chmod (777).
How to manage pages?
The feature which will be able to do that you can find in Manifest file. I’ve noticed it is a very important file, something similar to file which defines how to run application, I guess. In my case I wanted to get some pages (Main and Help/Configuration). So then my Manifest file looks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="sendto.server" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".SendToServerActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="HelpActivity"></activity> </application> </manifest> |
What exactly I mean by “Pages”, you can find out by clicking link below:
Rolandas
/ June 18, 2013Applicattion for Source code not work. Eclipse write : “Corresponding method handler ‘public void HelpActivity(android.view.View)’ not found” . So HelpActivity in source code not found :((( Please help me…
Licryle
/ November 8, 2015Hey there,
Since I’ve been looking all over the web for an up to date (HttpClient & HttpPost are deprecated), I’ve ended up coding my own small library! Hoepfully that can help someone: https://github.com/licryle/HTTPPoster
cheers
Fast crdit onine
/ February 4, 2016In my opinion, if all web owners and bloggers
made excellent content material as you did, the net can be much more useful than ever before.
Virginia loans fast
/ February 6, 2016Greetings from Florida! I’m bored to tears at work so I decided to check out your blog on my iphone during lunch
break. I love the knowledge you present here and can’t
wait to take a look when I get home.
Home loan Tulsa
/ February 8, 2016I must say you’ve done a fantastic job with this.
Online home credit
/ February 14, 2016I am really enjoying thedesign of your weblog. I have read some good stuff here.
ogłoszenia z całej Polski
/ April 9, 2016Wow! Finally I got a weblog from where I be able to really get helpful data concerning my study and knowledge.
บาคาร่าออนไลน์
/ May 8, 2017This is a good code
ทางเข้าจีคลับ
/ May 8, 2017l ike this page
soo good
บาคาร่าออนไลน์
/ May 9, 2017I like this page soo good
บาคาร่าออนไลน์
/ May 9, 2017this pages is good
บาคาร่าออนไลน์
/ May 9, 2017this page
บาคาร่าออนไลน์
/ May 9, 2017hi friend …..
83Flossie
/ August 11, 2017Hello admin, i must say you have hi quality posts here.
Your website should go viral. You need initial
traffic only. How to get it? Search for: Mertiso’s tips go viral
WilliamNaf
/ January 27, 2020Siemano, może ktoś polecić kolagen z tołpygi?Potrzebuję takiego do smarowania na ciało, ze względów sportowych.
Njgrckxwic
/ June 23, 2021Njgrckxwic https://usryzhqqtx.net/