我试图将数据发送到MySQL数据库,但是却出现了这个错误。
W/gralloc_ranchu: Gralloc pipe failed
[ 12-26 22:08:05.136 2393: 2393 D/ ]
HostConnection::get() New Host Connection established 0xa998dd80, tid 2393
这是我的安卓代码
public RequestQueue reguestQueue;
public String insertUrl = "10.0.2.2/beacon/insertBeacon.php"; // local ip adresi yaz
private Handler mHandler = new Handler();
private void startTime() {
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postDelayed(mUpdateTimeTask, 100);
}
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
// buraya ne yapmak istiyorsan o kodu yaz.. Kodun sonlandıktan sonra 1 saniye sonra tekrar çalışacak şekilde handler tekrar çalışacak.
StringRequest request = new StringRequest(Request.Method.POST, insertUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> parameters = new HashMap<String, String>();
parameters.put("firstname","Serkan");
parameters.put("lastname","BAYRAM");
parameters.put("age","19");
return parameters;
}
};
reguestQueue.add(request);
mHandler.postDelayed(this, 1000);
}
};
答案 0 :(得分:0)
试试这个
InputStream iss = null;
int code;
int done = 0;
String result = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("firstname", "Serkan"));
nameValuePairs.add(new BasicNameValuePair("lastname", "BAYRAM"));
nameValuePairs.add(new BasicNameValuePair("age", "19"));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("10.0.2.2/beacon/insertBeacon.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
iss = entity.getContent();
} catch(Exception e) {
Log.e("pass 2", "Connection Error");
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader
(new InputStreamReader(iss,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
sb.append(line + "\n");
iss.close();
result = sb.toString();
} catch(Exception e) {
e.printStackTrace();
}
try {
JSONObject json_data = new JSONObject(result);
code=(json_data.getInt("code"));
if(code==1){
done = 1; //values inserted successfully
}
else
done = 0; //values not inserted successfully
} catch(Exception e) {
e.printStackTrace();
}
以json格式从insertBeacon.php
返回1或0