首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送信号。PID: 6939 SIG: 9,带zxing二维码扫描仪

发送信号。PID: 6939 SIG: 9,带zxing二维码扫描仪
EN

Stack Overflow用户
提问于 2019-05-29 01:02:21
回答 2查看 792关注 0票数 0

我正在开发一个内置二维码阅读器的应用程序,扫描完代码后,我必须启动另一个活动(名为CodaActivity.class),并从qrcode中获取一个参数。

我从这里找到的一个教程开始:(https://www.androidtutorialonline.com/android-qr-code-scanner/),并尝试根据我的需要对其进行自定义。

这是QRCodeScannerActivity的代码:

代码语言:javascript
复制
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();

    }


}

但在我扫描二维码(当然是使用物理设备)之后,debbugger退出,并显示以下消息:

代码语言:javascript
复制
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.

手机中的应用程序仍然处于打开状态,但会转到不同的活动。为什么?以及为什么我没有得到错误!感谢您的回复

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-29 16:02:25

经过多次测试和使用另一部手机(使用oreo),我最终发现拆分字符串是错误的,令牌是错误的,但对于前一部手机(android 6)没有抛出异常,所以我无法弄清楚发生了什么。此外,更仔细地查看代码,我在startActivity ()调用之前插入了finish ()语句...

我希望这能帮助到一些人。

票数 0
EN

Stack Overflow用户

发布于 2021-04-18 12:47:33

我希望这能帮助到一些人,我花了更多的时间来找出你应该使用正确的版本:^1.0.1,并将其添加到pupspec.yaml中,如下所示:

代码语言:javascript
复制
dependencies:
  flutter:
    sdk: flutter

  flutter_barcode_scanner: ^1.0.1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56347019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档