我是android开发的初学者。我不知道如何使用凌空上传特定路径(例如“ mnt / sdcard / file.xxx”)到我的php服务器中的文件。我如何能够使用凌空将文本数据上传到我的php服务器。这是我使用的代码,在我从服务类中调用pploadFile(“ sdcard / file.xxx”)的地方。
public class UploadFiles extends Application{
RequestQueue queue;
JsonObjectRequest request;
Map<String, String> map = new HashMap<String, String>();
public void pploadFile(String path){
Log.e("Upload Class","Inside Upload Class");
try {
queue = Volley.newRequestQueue(this);
Log.e("Upload Class","Inside Upload Class1");
// the parameters for the php
// map.put(KEY, VALUE);
map.put("email", "example");
// map.put("file", "");
// the JSON request
// JsonObjectRequest(METHOD, URL, JSONOBJECT(PARAMETERS), OK_LISTENER, ERROR_LISTENER);
request = new JsonObjectRequest(
Request.Method.POST, // the request method
"http://192.168.0.118/recieve.php", // the URL
new JSONObject(map), // the parameters for the php
new Response.Listener<JSONObject>() { // the response listener
@Override
public void onResponse(JSONObject response) {
// here you parse the json response
}
},
new Response.ErrorListener() { // the error listener
@Override
public void onErrorResponse(VolleyError error) {
/* here you can warn the user that there
was an error while trying to get the json
information from the php */
}
});
// executing the quere to get the json information
queue.add(request);
}catch (Exception e){
Log.e("Volley Err",e.getMessage());
}
}