【问题标题】:Zxing lib. does not work above Android MZxing 库。不适用于 Android M 以上
【发布时间】:2017-11-13 12:05:15
【问题描述】:

我已经成功地将 zxing core.jar 库集成到了 android Marshmallow 之下,但是在将其集成到 Marshmallow 之上时,它给了我以下错误:

android.content.ActivityNotFoundException: NO activity found to handle
intent{act=com.google.zxing.client.android.SCAN}

提前致谢。

【问题讨论】:

  • 您可以检查并发布您项目中的合并清单吗? => stackoverflow.com/questions/32087870/…
  • 是的。但是当我从 core.jar 库注册 CaptureActivity 时,它给了我错误。未找到活动。
  • 如果没有像清单这样的更多代码,我们无法为您提供帮助 :)

标签: android android-6.0-marshmallow zxing


【解决方案1】:

@凯文·罗巴特尔 我的清单

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

下面的代码执行按钮的onClick

try {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        //intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
        startActivityForResult(intent, BARCODE_CAPTURE_ACTIVITY);
    } catch (ActivityNotFoundException anfe) {
        Toast.makeText(mContext, "Scanner Not Found "+anfe.toString() , Toast.LENGTH_LONG).show();
    }

【讨论】:

    【解决方案2】:

    我认为问题可能出在相机的运行时权限上。尝试以代码或手动方式授予对您应用的访问权限

    【讨论】:

      【解决方案3】:

      您应该在 Manifest 文件中编辑代码:

      <activity
                  android:name="com.google.zxing.client.android.CaptureActivity"
                  android:configChanges="orientation|keyboardHidden"
                  android:screenOrientation="landscape"
                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                  android:windowSoftInputMode="stateAlwaysHidden" >
                  <intent-filter>
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.LAUNCHER" />
                  </intent-filter>
                  <intent-filter>
                      <action android:name="com.google.zxing.client.android.SCAN" />
                      <category android:name="android.intent.category.DEFAULT" />
                  </intent-filter>
              </activity>
      

      别忘了添加权限:

      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.CAMERA"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-27
        • 2018-10-01
        • 1970-01-01
        相关资源
        最近更新 更多