首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NFC标签和php

NFC标签和php
EN

Stack Overflow用户
提问于 2013-09-17 17:34:21
回答 2查看 2.4K关注 0票数 1

我是NFC标签的新手,对它的工作原理很感兴趣。我已经买了一个NFC标签,并且能够向标签中写入studentid。现在我的问题是如何将学生号传递到php web服务,并在通过我的应用程序扫描他们的学生卡之前检查这个学生是否已经支付了他/她的餐费。

好心的人可以帮助我如何做这件事。下面是我所做的。

代码语言:javascript
复制
//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());
            }

    }
EN

回答 2

Stack Overflow用户

发布于 2014-01-15 22:46:05

据我所知,至少对于android阅读器,如果标签包含URL,它会自动加载浏览器并转到URL (不会询问您是否要打开应用程序,也不会询问您是否要转到URL)。您应该能够将student_id作为查询字符串放在页面中使用。

票数 0
EN

Stack Overflow用户

发布于 2015-04-29 19:20:21

这里有一个NDEF实现的例子:Github repo

在主活动中,您必须修改

代码语言:javascript
复制
@Override
    public void ndefDataRead(String ndefData) {
    demoTextView.setText(ndefData);
}

调用getstudentinfo(String studID)方法,它可能会起作用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18846228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档