将Qr-Code-Scanner-App连接到MySQL数据库

时间:2019-05-18 12:04:17

标签: java mysql json database

我正在尝试将我的Qr-Code-Scanner-App连接到MySQL-Database。但是不知何故,它不起作用。有人知道为什么吗?我已经尝试了我所知道的一切:( (我仍然是初学者,因此,如果这是一个基本问题,很抱歉:) 最好的祝福 getNordic

public void Scan(View v)
{
  try {

    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes

    startActivityForResult(intent, 0);

} catch (Exception e) {

    Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
    Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
    startActivity(marketIntent);

}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {           
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {

    if (resultCode == RESULT_OK) {
        String contents = data.getStringExtra("SCAN_RESULT");//Value retrieved from qr code is stored in this string
    }
    if(resultCode == RESULT_CANCELED){
        //handle cancel
    }
}
}

public String makePOSTRequest(String url, List<NameValuePair> nameValuePairs) {
String response = "";

try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
Log.d(LOGTAG, "POST Response >>> " + response);
return response;

}

这是PHP代码:     

// $data holds your data from the android app
// Perform your db query here

$result = ["Resultdata" => $dbresult];
print json_encode($result);
?>

0 个答案:

没有答案