![](/img/trans.png)
[英]How can i get data latlng that i saved in firebase when it trigger by marker android studio
[英]Android Studio - How can I trigger an intent when an 'if' is fulfilled
我已经设法获得了由Google Vision驱动的二维扫描仪,并将该二维码放入同一活动的文本视图中。
最终目标是,一旦检测到qrcode,就会在另一个活动(QRWebActivity)的Web视图中打开qrcode中的url。
在此阶段,我能够使用单击按钮上sendMessage2激活的意图将qrcode移至字符串中并推入并在Web视图中打开。
但是我真的很想找到一种方法,使其自动打开QRWebActivity并将webview发送到'if(qrCodes.size()!= 0)上的qrCode。
任何帮助都将是惊人的。
非常抱歉,如果我使用的术语不正确,我只是不知道自己在做什么,但真的很想在本周末完成该应用程序的发布,所以我非常接近。
barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
@Override
public void release() {
}
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if(qrCodes.size()!=0)
{
textView.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
textView.setText(qrCodes.valueAt(0).displayValue);
}
});
}
}
});
}
public void sendMessage2 (View view)
{
String qrmessage = textView.getText().toString();
Intent intent2 = new Intent(view.getContext(),QRWebActivity.class);
intent2.putExtra("EXTRA_QRMESSAGE",qrmessage);
startActivity(intent2);
}
}
如果我可以模拟当qrCodes!= 0时按下按钮并触发“ sendMessage2”,那将对我有帮助...即使我确定还有更优雅的方法。
根据您的代码,这是我的解决方案:
@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if (qrCodes.size() != 0) {
textView.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
textView.setText(qrCodes.valueAt(0).displayValue);
sendMessage2(textView);
}
});
}
}
所有代码已经在那里,只是不要将其拆分:
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> qrCodes = detections.getDetectedItems();
if(qrCodes.size()!=0)
{
Intent intent2 = new Intent(view.getContext(),QRWebActivity.class);
intent2.putExtra("EXTRA_QRMESSAGE",qrCodes.valueAt(0).displayValue);
startActivity(intent2);
textView.post(new Runnable() {
@Override
public void run() {
Vibrator vibrator = (Vibrator)getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
textView.setText(qrCodes.valueAt(0).displayValue);
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.