【问题标题】:Is there anyway to send the scanned QR code results directly to the server?有没有办法将扫描的二维码结果直接发送到服务器?
【发布时间】:2015-09-03 06:06:29
【问题描述】:

我开发了一个用于扫描二维码的安卓应用并通过服务器发送。 在这个应用程序中,我使用数组列表在列表视图中获取多个 QR 码扫描结果,并通过按钮单击事件将它们发送到服务器。 要求是将所有扫描的二维码结果直接发送到 服务器不使用任何事件,例如按钮单击或类似的事件。 在这里,我使用意图使用 zxing QR 扫描仪。下面是获取二维码扫描结果的代码。

       @Override
       public void onActivityResult(int requestCode, int resultCode, Intent intent) {
       if (requestCode == SCANNER_REQUEST_CODE) {
        // Handle scan intent
        if (resultCode == Activity.RESULT_OK) {
            // Handle successful scan
            String contents = intent.getStringExtra("SCAN_RESULT");
            String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
            byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
            int intentOrientation = intent.getIntExtra(
                    "SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
            Integer orientation = (intentOrientation == Integer.MIN_VALUE) ? null
                    : intentOrientation;
            String errorCorrectionLevel = intent
                    .getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");

            QRContent = contents;
            QR_Receivd.setText(QRContent);
            listItems.add(QRContent); //adding scan result to an array list(listItems)

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Handle cancel
        }

     //On-click method to initiate scan.

     @Override
    public void onClick(View v) {
    if (v.getId() == R.id.btScan) {
    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
    intent.putExtra("SCAN_MODE", "SCAN_MODE");
    startActivityForResult(intent, SCANNER_REQUEST_CODE);
   }  
 }

所以我不想使用点击事件我想在从扫描仪获得结果后立即将扫描结果直接发送到服务器。 谢谢!!!

【问题讨论】:

    标签: java android qr-code zxing


    【解决方案1】:

    第 1 部分

    首先,您应该选择发送方式。您可以使用官方工具或使用 3rd 方库发送它。我会假设后者。

    根据我的方法,您需要在服务器上安装一个 PHP 文件,负责接收(通过 GET 或通过 POST)扫描的 QR 作为参数。

    示例调用:

    myserver.com/API/addqr?qrcode=XXXXXXXXXX

    这个 PHP 文件必须保存到您的数据库中,我想是 MYSQL。

    第 2 部分

    现在您已经设置了服务器,您应该查看不同的库或官方文档。

    USING VOLLEY

    Using Loopj's Android Async HTTP petitions (i reccomend this)

    我假设你选择方法 2。

    您所要做的就是发送请愿书:

        if (resultCode == Activity.RESULT_OK) {
                //blah blah blah all the code that decodes and adds it to the listview
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
            params.put("qrcode", "XXXXXXXXXXXXX");
     client.post("myserver.com/API/addqr", params, new JsonHttpResponseHandler() {
    
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
              //do something with the response, if there is one.
            }
    
        });
    
            }
    

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多