我正在使用zxing库提供qrcodes并扫描到应用程序但是我遇到了问题。 在尝试扫描时,我尝试了几种方法。 推荐:
IntentIntegrator integrator = new IntentIntegrator(this); integrator.initiateScan();或Intent方法:
Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); this.startActivityForResult(intent, 0);两者似乎都可以正常工作,因为扫描应用程序或选择应用程序来处理意图对话框出现。 但是,扫描后,应用程序立即关闭。 没有错误也没有结果。 再见。
捕获结果的方法,在从不显示super()之后立即记下Log.d。
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(LOG_TAG, "resultcode = " + resultCode); switch (requestCode) { case IntentIntegrator.REQUEST_CODE: IntentResult scanResult = IntentIntegrator.parseActivityResult( requestCode, resultCode, data); if (scanResult == null) { return; } final String result = scanResult.getContents(); // Your result if (result != null) { Log.d(LOG_TAG, "Your result is: " + result); } break; default: } }我在一些教程中看到过引用,解释了如何在AndroidManifest.xml中实现zxing make条目。 见如下:
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" 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.DEFAULT"/> </intent-filter> <intent-filter> <action android:name="com.google.zxing.client.android.SCAN"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>到目前为止,我只是没有运气,缺少日志并没有帮助我指向任何方向。
我正在使用Android Studio,并为依赖项中的lib设置了gradle:
compile files('libs/core-3.1.1.jar') compile files('libs/android-integration-3.1.1.jar')非常感谢帮助。
I'm using the zxing library to provide qrcodes and scanning to an application however I'm stuck on an issue. When attempting to scan, I've tried several methods. The recommended:
IntentIntegrator integrator = new IntentIntegrator(this); integrator.initiateScan();or the Intent method:
Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); this.startActivityForResult(intent, 0);Both appear to work fine as the Scan app or choose the app to handle the intent dialog appears. However, after scanning, the app immediately closes. No errors and no results. Just bye-bye.
method to catch the result, note the Log.d immediately after super() is never displayed.
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(LOG_TAG, "resultcode = " + resultCode); switch (requestCode) { case IntentIntegrator.REQUEST_CODE: IntentResult scanResult = IntentIntegrator.parseActivityResult( requestCode, resultCode, data); if (scanResult == null) { return; } final String result = scanResult.getContents(); // Your result if (result != null) { Log.d(LOG_TAG, "Your result is: " + result); } break; default: } }I've seen references in some tutorials explaining how to implement zxing make entries in the AndroidManifest.xml. Seen below:
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" 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.DEFAULT"/> </intent-filter> <intent-filter> <action android:name="com.google.zxing.client.android.SCAN"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>I'm just not having any luck so far and the lack of logs isn't helping point me in any direction.
I'm using Android Studio and have gradle setup for the libs in dependencies:
compile files('libs/core-3.1.1.jar') compile files('libs/android-integration-3.1.1.jar')Help is really appreciated.
最满意答案
问题不在于zxing,而在于你开始它的方式。 startActivityForResult方法的第二个参数是requestCode ( 文档 )。 然后,您将检查onActivityResult上的requestCode以处理响应。 另外,不要在onActivityResult调用super 。
例如:
startActivityForResult(intent, 123);将导致Android使用请求代码123调用onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 123 && resultCode == RESULT_OK) { //do some stuff... } else { super.onActivityResult(requestCode, resultCode, data); } }The problem is not with zxing, but rather with the way you start it. The second parameter of the startActivityForResult method is a requestCode (documentation). You would then check that requestCode on onActivityResult to handle the response. Also, do not call super first in onActivityResult.
For example:
startActivityForResult(intent, 123);will cause Android to call onActivityResult with request code 123
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 123 && resultCode == RESULT_OK) { //do some stuff... } else { super.onActivityResult(requestCode, resultCode, data); } }更多推荐
发布评论