I have a web written in Django framework and created Rest Framework for the API.
I am required to write an android application based on the Django framework (Android and Django newbie).
However I do not know how to pass the data from android (user input) into database MYSQL through Django Rest Framework. I done a lot of research in past 2 weeks, but still I cannot see any solution (text tutorial, video tutorial, code example) related to this issue.
Note: I will not using any PHP script and looking forward integrate with Django Rest Framework.
Let's have a testing example API from Django : http://json-api.jerel.co/entries
User input field from android: blog, headline, body text, pub date, mod date, authors
Which class/library in android involved? Volley? httpUrl? Json?
I appreciate that anyone can share a simple code to get this done.
======================================================================
FYI,
Database: MYSQL
Server : CentOS
Web : Python - Django
Android : Android studio
============================================================================
After tried all the solutions on net, and excluded those apache http client deprecated post, this is the workable and simplest solution (in my opinion):
https://stackoverflow.com/a/33937147/2466516
Thanks to Nitro.
#chan-hau-yeen, you will want to look at something like Retrofit2 for Android to handle the network post to your Django backend. You can create json objects to post to your backend. Then with django you can accept the json and handle it there.
Once you have created api end points using DRF with data in json . You can use volley library for handling network calls .
Here is the link which shows how make network calls and json parsing .
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/
Related
I'm currently working on an android project. And I want to upload some data from android app to (web(using bootstrap)+API)_(Laravel). My lecturor said that now I have to write code API to manage datas but I don't know how to do that. I searched so much but my results that build GET, POST, EDIT, DELETE and build Controller for Laravel project. How should I do? Thanks in advance.
You can use Volley to manage Http requests and responses to the laravel server. And use Gson for managing JSON objects from the android application.
Make a JSON object containing the data you want to send and return the JSON string from the Laravel application.
I'm new to android, I'm trying to build an android app that is a front for a web portal. For example, Airbnb. They have a website, but they also have an android app that, using it's own layout, will show listings from their website.
There are many websites that teach how to or even directly convert your website to android apps. However, this will result in an app that loads too slowly and is unresponsive due to CPU usage.
Could anyone share any tutorial/guide to learn how to do this myself?
Million thanks.
To actually load data from a web server you're gonna need and API which usually delivers the proper date using JSON or XML format so that you can properly parse and display that data. Building this API is in it self a complete course on its own.
But connecting to and requesting data from the API is usually done using some networking libraries. These are some of the better know libraries for this purpose.
OkHttp: A complete library with a set of tools for handling network connections and HTTP requests.
RetroFit:Type-safe HTTP client for Android and Java by Square, Inc. which is built on top of OkHttp.
Async-Http-Client:
The Async Http Client library's purpose is to allow Java applications
to easily execute HTTP requests and asynchronously process the HTTP
responses. The library also supports the WebSocket Protocol. The Async
HTTP Client library is simple to use.
There tons of other good libraries.
its called webservices
Through android you get data in form of json from a web server and then return in custom view as you want.
Follow this link hope it will help
Step by Step Method to Access Webservice from Android
you would have to write an API/Web service or use if already exits to fetch data from web server. Basically the concept is that, the website itself must be pulling data from some database, so write an API which would fetch the data from same API and return JSON data and consume the API from your android app.
If you know PHP refere to this for the help :http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
You can write WebService, in programming it generally refers to a web page(ex. Airbnb), that can be called from your android application which can pass in data to it, or receive data from it.
WebService is basically like a 'method' or 'function' in a normal programming language; except you're calling it over the internet.
The first thing is you have to create a Web Service. The Web Service will be your "bridge" to consume the data from other Website like airbnb or others and return the data to your android through json format for example.
You can create a Web Service using many languages like C#, Java, PHP, etc. I would like to recommend you to use the language that you know the most.
You can try to google this
Cheers
I am new to socket programming i have to use socket.io and node.js to connect with my server host in android so can anyone please just describe me the programming example of how to connect to server in android. And if possible please give some help regarding node.js and socket.io. As i have searched everywhere on google but not able to find out the proper example.
Thanks
You can just have your web service be REST base.
Your Android application can just talk to your web server via REST and receive data json or xml whatever you fancy.
So with node.js you should set up routes.
An example would of a route would be
www.example.com/users via GET post would return a list of users either in JSON/XML
For your android application you need a library, I believe there's a built in one already, to make request for certain routes such as www.example.com/users via GET method and write the logic to expect JSON or XML and parse that.
I just googled this:
Android: https://github.com/koush/ion
As for node.js you just have to build route...
I think is would be better:
websocket api to replace rest api?
It actually invalidate my answers sorry, REST and websocket api are different.
I have no clue what problem exactly you have. But you should break your problems down to small part. And google and search for answer for each smaller part which would make your life easier to google.
Get your webservice up first so that your android software can consume stuff, build a prototype and then build a prototype of android app that consume data from that webservice.
im wondering the easiest way to go about this. I've used retrofit for java before to post and get from endpoints in web service my friend wrote in python.. However I've never wrote server side stuff. I have phpmyadmin running on a vitural server... Havnt used it yet however. I just need people to be able to like or dislike a poem they get from the server. Is there anything on the web I could set up like database I can alter from its endpoint? Or am I going to have to learn php and python now? Thanks guys!
To develop a web service is not necessary use php or python. If you are used to programming in Java I recommend you to use Jersey (https://jersey.java.net/) which offers an easy way to define your endpoints. You can also use jackson (http://jackson.codehaus.org/) to process the json info between client and server. Jackson helps you to transform a collection of object form JSON and vice versa.
I'm a newbie when it comes to client/server apps but I have an idea for an app but need a few ideas on how to implement it. I want users to be able to submit say a post and the server would store it. Other users will be able to also submit posts...the posts will then be able to be viewed as a list updated from the server. What is the best way to ndo this with android? JSON? SQL? What have you found easy? Thanks any suggestions are much appreciated!
Write a server component with your app-specific services, such as creating a post, retrieving all posts, etc. JSON is a simple and good choice.
Use DefaultHttpClient or AndroidHttpClient for communicating with your server via HTTP:
http://developer.android.com/reference/org/apache/http/impl/client/DefaultHttpClient.html
http://developer.android.com/reference/android/net/http/AndroidHttpClient.html
http://developer.android.com/reference/android/net/package-summary.html
Use the org.json package to create requests and parse responses:
http://developer.android.com/reference/org/json/package-summary.html
These packages and classes are basically available on all Android devices, and they are fairly easy to use.
DefaultHttpClient or AndroidHttpClient for communication
Android JSON library or for large data Jackson Streaming API
SQLiteDatabase
C2DM to push messages or Deacon project for custom server
Everything is built into Android SDK except Jackson and Deacon