基本上你要做的是创建一个简单的服务器-客户端架构。
有多种方法可以做到这一点。我将解释使用NodeJS 作为服务器和客户端(android)端的截击。
首先,您可以使用Volley,从android 创建一个API 调用,该调用将与NodeJS API 交互,这反过来将创建数组并将其存储为SQL 或您想要的任何其他形式。
作为参考,您可以查看这两个项目。
这是一个Android app,它使用 Volley 与服务器通信。
这是NodeJS Server,它是一个简单的 REST API。
如果您不知道,也可以使用此link 来学习有关 NodeJS 的基础知识。
这是创建服务器然后向客户端发送响应的基本 NodeJS 代码。
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response to the client
res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
这是向服务器发出请求的基本 Android Volley 代码。
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://www.google.com";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
textView.setText("Response is: "+ response.substring(0,5));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
如果您不理解这些代码中的任何一个,可以在下面发表评论。