I need to send all my contacts to server and return back only the contacts that are using my app.I am using HttpPost for sending data to the server. I am thinking of sending it as an string separated by delimiters or as NameValuePair. Is there any better way to do contact sync?
Are you using a database? If so create a php webservice that connect to your database, make a query and return results according the criteria you need. then you need to encode the result in a json array and use json to connect your android app and get the results, here is an example how to use json with android:
http://www.vogella.com/articles/AndroidJSON/article.html
There are many more libraries you can use: gson/json/jackson... all similar, you can make a search on google and chose the one you like better
Instead of json you can use SOAP, I have never used it but you can try : http://code.google.com/p/ksoap2-android/
Direct database connection is not recommended on android
Related
i have a Application with a database and i want update the database from net
i used downloading whole database and extract file in database folder but some time get wrong I'd like some advice if there is a better way to do it
You need to create a webservice. This can be done in PHP (I also use RESTful Api's). These services will return JSON which you can parse through.
Try this out:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
I'm making an android app that will have a backend database (MySQL).
From my research, it seems like one of the ways to connect to a MySQL database is to use PHP to make an HTTP request to the database, which will then return data in the form of a JSON object which is decoded.
PHP is used to make a GET/POST to the database (often using a service like Retrofit)
The database fetches or posts the appropriate data and must alert the client/return data
The database sends back information that is JSON form
The client decodes the returned JSON
Is this the correct logic?
Why is PHP needed to make the request? Is this an acceptable way of interacting with a MySQL database from an android app? Do you have any advice to offer for going about this?
If your are using the LAN MYSQL server in your own device, you can use MYSQL command to connect the server
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://"+serverip+":"+serverport+"/"+dbName;
Connection conn = DriverManager.getConnection(url,username,password);
String queryString = "SELECT * FROM materialdb";
PreparedStatement statement = conn.prepareStatement(queryString);
ResultSet rss = statement.executeQuery(queryString);
results = new ArrayList<FindDetails>();
rss.beforeFirst();
while(rss.next())
{
FindDetails item_details = new FindDetails();
item_details.setMaterial_Code_No(rss.getString("Material_Code_No"));
results.add(item_details);
}
rss.close();
statement.close();
}
catch(Exception e)
{
Toast.makeText(this, "Fail to get main list", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
If the server is on web, the better way of connect to server is PHP
This approach looks like it is for a web server, not a client (much less an Android client). Usually, servers have databases and clients are "consumers" of that data. However, clients also usually have databases to store that data.
PHP is a server-side technology whereby you can use a URL and HTTP to send and retrieve data. PHP can then be used to connect to a database to provide rich content to the client.
In Android, your device (likely) will not have a URL or website. It can have a database and you can use HTTP libraries (like Retrofit - http://square.github.io/retrofit/) to get data from websites (that might use HTTP). But this is passive - your client will have to request data, the server cannot "push" data to it.
For "push" data, you can use Firebase (Google Cloud Messaging) which uses a Google framework and API to have a (reasonably) constant connection to the device to "push" notifications to it. If you follow their rules, you will send a small data packet that tells your client to wake and start making specific HTTP requests to whatever URL you like.
I have a doubt actually regarding volley in android. I know how to fetch data from sql server database through php code which does not take any data from the android app like
select * from table;
and if I'd like to fetch data from database with php code containing statements like
select * from tablename where field1='something';
I need to send data from android app to php. Can we actually do it using Volley. If so please tell me how to send data to php file from android.
HTTP library that you are using is not relevant in this problem. You need to allow for data input in PHP script. Either by POST or GET variables. (look at this tutorial http://www.tutorialspoint.com/php/php_get_post.htm)
In terms of creating request with proper parameters take a look at this question: Volley - POST/GET parameters
Sure you can.
Follow the official Volley guide, here
I am working on an Android app where the user fills a form and submits it. I want to know which technique to use to store the data. I want to later process this stored data to form reports. Please suggest me the best way to store data and later to produce report.
The form initially will contain one dropbox, date, radio button and edit text.
I found few options below but dont knw how to proceed:
Using JSON
Using Google cloud
I tried code at below link:
http://androidexample.com/How_To_Make_HTTP_POST_Request_To_Server_-_Android_Example/index.php?view=article_discription&aid=64&aaid=89
But dont know how to run the program as it needs serverside php script. I have XAMPP installed on my machine with Apache server running. I can run normal php code but dont know how to make that php code work with my android app.
I am new to server side data handling
Thank you very much in advance. Please help
since you're working with xampp.you can access your localhost from your android emulator using the ip 10.0.2.2/
you will need to use the AsyncTask class and a JSON parser to send your data to your php script.The JSONparser class will remain constant for most of your whole app. You will only have to change the code in your AsyncTask class depending on what data you want to send and the location(php file ie 10.0.2.2/your_file.php or yourdomainname.com/your_file.php) to process the data.
If you don't want to work on server scripting and requires a simple data storage to the cloud then you can try using Parse
Basically Parse provides you with a library that your app can use to pass values to the server Parse is managing.
I want to get JSON data from an server and store it to database on my server.
I bought API that returns json, which means that server is not mine but I want to take that data and store it to my server.
How to call API, receive data and store it to my server?
P.S. That API only allows access from 5 IP addresses and I want to use it for android app. Instead of getting data directly from that server to android phone, I have to store that data to my server and then call GET method on my server to receive results on the android phone. This way I could even use GCM.
It doesn't have to be php script. If you have better idea or solution please let me know.
You could use
$json = json_decode(file_get_contents("http//example.com/path?query"));