0

在我的应用程序中,我尝试调用结果的意图,但它显示“未找到活动异常”。

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
4

1 回答 1

1

可能没有安装扫描仪?尝试这个:

if (checkpackage(context, "com.google.zxing.client.android")) {
        ((Activity) c).startActivityForResult(new Intent("com.google.zxing.client.android.SCAN"), 0);
    } else {
        Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri);
        ((Activity) c).startActivity(marketIntent);
        Toast.makeText(c, "Es ist kein Barcodescanner installiert", Toast.LENGTH_SHORT).show();
    }

public static boolean checkpackage(Context ctx, String PACKAGE_NAME) {
    try {
        PackageInfo info = ctx.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
        return info != null;

    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
于 2012-06-04T14:22:54.670 回答