Hye,我的Android应用程序有问题。此应用程序用于扫描来自信标和eddystone的数据,数据将保存到本地文件和服务器。我使用齐射字符串请求方法来获取数据,并不确定这是否正确.apk已成功构建但我的服务器没有收到数据。它只是空白。非常感谢你们能帮助我。
这是我发送数据的mainactivity.java部分。
private void stopScanning(Button scanButton) {
try {
beaconManager.stopRangingBeaconsInRegion(region);
} catch (RemoteException e) {
// TODO - OK, what now then?
}
String scanData = logString.toString();
if (scanData.length() > 0)
{
String url = "http://beaconscanner.byethost33.com/insertbeacondata.php";
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
protected Map<String, String> getParams()
{
Map<String,String> params = new HashMap<String, String>();
// the POST parameters:
params.put("scanInterval",PREFERENCE_SCANINTERVAL);
params.put("timestamp",PREFERENCE_SCANINTERVAL);
params.put("power",PREFERENCE_POWER);
params.put("proximity",PREFERENCE_PROXIMITY);
params.put("rssi",PREFERENCE_RSSI);
params.put("majorMinor",PREFERENCE_MAJORMINOR);
params.put("uuid",PREFERENCE_UUID);
params.put("index",PREFERENCE_INDEX);
params.put("location",PREFERENCE_LOCATION);
params.put("realTimelog",PREFERENCE_REALTIME);
return params;
}
};
Volley.newRequestQueue(this).add(postRequest);
// Write file
fileHelper.createFile(scanData);
// Display file created message.
Toast.makeText(getBaseContext(),
"File saved to:" + getFilesDir().getAbsolutePath(),
Toast.LENGTH_SHORT).show();
scanButton.setText(MODE_STOPPED);
} else {
// We didn't get any data, so there's no point writing an empty file.
Toast.makeText(getBaseContext(),
"No data captured during scan, output file will not be created.",
Toast.LENGTH_SHORT).show();
scanButton.setText(MODE_STOPPED);
}
}
这是php编码:
if($_SERVER['REQUEST_METHOD']=='POST'){
$dataScan = $_POST["scanInterval"];
$dataTime = $_POST["timestamp"];
$dataPower = $_POST["power"];
$dataProx = $_POST["proximity"];
$dataRssi = $_POST["rssi"];
$dataMajmin = $_POST["majorMinor"];
$dataUuid = $_POST["uuid"];
$dataIndex = $_POST["index"];
$dataLoc = $_POST["location"];
$dataReal = $_POST["realTimeLog"];
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO beaconscanner (scanInterval, timestamp, power, proximity, rssi, majorMinor, uuid, index, location,
realTimelog) VALUES ('$dataScan', '$dataTime', '$dataPower', '$dataProx', '$dataRssi', '$dataMajmin', '$dataUuid', '$dataIndex',
'$dataLoc', '$dataReal',)";
if ($conn->query($sql) === TRUE)
{
echo "Record updated successfully";
}
else
{
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
?>