[英]Sending signal. PID: 6939 SIG: 9 with zxing QR code scanner
我正在开发一个带有嵌入式二维码阅读器的应用程序,在扫描代码之后,我必须使用从二维码中获取的参数启动另一个活动(名为 CodaActivity.class)。
我从这里找到的教程开始:( https://www.androidtutorialonline.com/android-qr-code-scanner/ )我尝试根据我的需要对其进行自定义。
这是 QRCodeScannerActivity 的代码:
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
import static android.Manifest.permission.CAMERA;
public class QrCodeScannerActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private static final int REQUEST_CAMERA = 1;
private ZXingScannerView mScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
if (checkPermission()) {
Toast.makeText(getApplicationContext(), "Permission already granted", Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
}
private boolean checkPermission() {
return ( ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA ) == PackageManager.PERMISSION_GRANTED);
}
private void requestPermission() {
ActivityCompat.requestPermissions(this, new String[]{CAMERA}, REQUEST_CAMERA);
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA:
if (grantResults.length > 0) {
boolean cameraAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (cameraAccepted){
Toast.makeText(getApplicationContext(), "Permission Granted, Now you can access camera", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "Permission Denied, You cannot access and camera", Toast.LENGTH_LONG).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (shouldShowRequestPermissionRationale(CAMERA)) {
showMessageOKCancel("You need to allow access to both the permissions",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{CAMERA},
REQUEST_CAMERA);
}
}
});
return;
}
}
}
}
break;
}
}
private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
new android.support.v7.app.AlertDialog.Builder(QrCodeScannerActivity.this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", null)
.create()
.show();
}
@Override
public void onResume() {
super.onResume();
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
if (checkPermission()) {
if(mScannerView == null) {
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
}
mScannerView.setResultHandler(this);
mScannerView.startCamera();
} else {
requestPermission();
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
mScannerView.stopCamera();
}
@Override
public void handleResult(Result rawResult) {
final String testoLink = rawResult.getText();
String[] risultato = testoLink.split(":");
risultato[1] = risultato[1].trim();
Log.e("QRCodeScanner", rawResult.getText());
Intent intent = new Intent(QrCodeScannerActivity.this, CodaActivity.class);
Bundle b = new Bundle();
b.putString("medico", risultato[1]);
intent.putExtras(b);
startActivity(intent);
finish();
}
}
但是在我扫描 QR 码(当然是使用物理设备)后,调试器退出并显示以下消息:
I/art: Object allocation is busy now, so prior to grow the heap. New heap size is 33 MB
I/art: current process_level is : 0
I/art: current process_level is : 0
I/art: current process_level is : 0
I/art: current process_level is : 0
I/art: current process_level is : 0
I/Process: Sending signal. PID: 8310 SIG: 9
Application terminated.
手机中的应用程序仍然保持运行状态,但会转到不同的活动。 为什么? 以及为什么我没有错误! 感谢您的任何回答
经过多次测试并使用另一部手机(带有奥利奥)我终于发现我错了拆分字符串,令牌错误但是对于之前的手机(android 6)没有抛出异常,所以我无法弄清楚是什么发生。 此外,更仔细地查看代码,我在 startActivity() 调用之前插入了 finish() 语句......
我希望这可以帮助某人。
我希望这可以帮助某人,我需要更多时间来找出它您应该使用正确的版本:^1.0.1 并将其添加到 pupspec.yaml 如下:
dependencies:
flutter:
sdk: flutter
flutter_barcode_scanner: ^1.0.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.