android - 如何将 QR 码结果发送到 TextView?
问题描述
我尝试将 QR 码结果发送到 textView。虽然相机正在运行,但扫描过程不支持,虽然功能不合适。没有显示错误消息......我该怎么办?
这是我的 QrActivity .....
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class QrActivity extends AppCompatActivity {
/**
* QR code declaration
*/
Button btnscan, btnSearch;
static TextView lblSearch;
@Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qr);
btnscan = (Button) findViewById(R.id.btnscan);
btnscan.setClickable(false);
btnSearch = (Button) findViewById(R.id.btnSearch);
btnSearch.setClickable(false);
lblSearch = (TextView) findViewById(R.id.lblSearch);
final Activity activity = this;
btnscan.setOnClickListener(new View.OnClickListener() {
@Override
public
void onClick(View v) {
btnscan.setClickable(true);
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(false);
integrator.initiateScan();
}
});
}
/**
* ---------------------------------------------------- QR code ----------------------------------------------------------
*/
@Override
protected
void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_SHORT).show();
} else {
/**
* Qr code result
* */
lblSearch.setText(result.getContents());
// Toast.makeText(this, result.getContents(), Toast.LENGTH_SHORT).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
/**
* -----------------------------------------QR scan-- Finished-------------------------------------*
* */
解决方案
推荐阅读
- kubernetes - Kubernetes:将传入流量路由到特定 Pod
- mime-types - 如何使用 com.filenet.wcm.api 更改 Filenet 文档 MimeType
- java - Hashmap 中一个键的值被设置为另一个键的值
- php - 比较字符串并删除部分字符串
- php - 循环遍历目录和子目录
- config - 为网络浏览器设置鱼而不是文本编辑器
- javascript - 在带有 {} 的 map() 中使用时反应不渲染元素
- android - 陀螺仪在三星和 Google Pixel 之间的行为不同
- vue.js - Vue JS路由用户角色,重载时丢失用户和数据
- laravel - 上下文感知本地化