我是 NFC 标签的新手,对它的工作原理很感兴趣。我已经购买了一个 NFC 标签,并且能够将 studentid 写入标签。现在我的问题是如何将学生 ID 传递给 php 网络服务,并在您通过我的应用程序扫描学生卡时检查该学生是否已经支付了他/她的餐费,然后您可以前往自助餐厅。
请任何人帮助我如何做到这一点。以下是我所做的。
//reading the tag
private String readText(NdefRecord record) throws UnsupportedEncodingException {
byte[] payload = record.getPayload();
// Get the Text Encoding
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
// Get the Language Code
int languageCodeLength = payload[0] & 0063;
// Get the Text
return new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
//show the student id in a textedit
mTextView.setText(result);
//pass variable to the server and get contents. I want to pass the student id to the method
getstudentinfo(result);
}
}
void getstudentinfo(String studID) {
//get connection to the server using http request
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://myip/getStudentBl.php?studID="+ studID);
try{
response = getThreadSafeClient().execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
//checking the response and info the user
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
}
});
//if the user is found
if(response.equalsIgnoreCase("Student Found")){
runOnUiThread(new Runnable() {
public void run() {
//Toast.makeText(MainActivity.this,"Saved Successfull", Toast.LENGTH_SHORT).show();
stdBalance.setText("Student Balance " + response);
}
});
//show the dashboard screen
startActivity(new Intent(MainActivity.this, MainActivity.class));
}else if(response.equalsIgnoreCase("No Record")){
//show error results
showAlert();
}
//end try catch
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
}