我遵循了一个教程,在该教程中,我使用Android Studio制作扫描仪,该扫描仪会将QR码保存到Activity_main.xml中的TextView中。到目前为止,它的工作原理是,当我在QR生成器站点中插入此{"name":"Gabriel","address":"NoNameStreet"}
时,在将要创建的QR代码的内容中,结果是它将在我之后在我的应用中设置名称和地址textview像这样扫描QR码。
但是,当我想在条形码生成器站点上添加相同的内容时,生成器不允许我使用某些字符,例如“,”或“ {”。是否有人现在可以生成条形码以得到相同的结果,或者是否必须以某种方式修改代码以解决该问题? 这是我在MainActivity.java中使用的代码
package com.example.androidscanner2;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private TextView textViewName, textViewAddress;
private IntentIntegrator qrScan;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewName = (TextView) findViewById(R.id.textViewName);
textViewAddress= (TextView) findViewById(R.id.textViewAddress);
qrScan = new IntentIntegrator(this);
}
public void scanQRCode(View view) {
qrScan.initiateScan();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if (result.getContents() == null) {
Toast.makeText(this, "Result not found", Toast.LENGTH_SHORT).show();
} else {
try {
JSONObject obj = new JSONObject(result.getContents());
textViewName.setText(obj.getString("name"));
textViewAddress.setText(obj.getString("address"));
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(this, result.getContents(), Toast.LENGTH_SHORT).show();
}
}
}else{
super.onActivityResult(requestCode, resultCode, data);
}
}
}