最近我正在创建条形码读取器应用程序,但不幸的是,在我的应用程序中无法初始化条形码检测器版本。当启动检测器时,应用程序将直接关闭。以前有人遇到过这个问题吗?
这是条形码处理的源代码
//process barcode
private void processData(Bitmap myBitmap){
BarcodeDetector barcodeDetector ;
try{
barcodeDetector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if(!barcodeDetector.isOperational()){
textview.setText("Could not set up the detector !");
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = barcodeDetector.detect(frame);
if(barcodes.size() > 0) {
try {
Barcode thisCode = barcodes.valueAt(0);
JSONObject jsonBObj = new JSONObject(thisCode.displayValue);
lodgingId = jsonBObj.getString(LodgingData.KEY_LODGING_ID);
userId = jsonBObj.getString(LodgingData.KEY_USER_ID);
textview.setText("data 1 : " + lodgingId + " data 2 : " + userId);
} catch (JSONException e) {
e.printStackTrace();
}
}else{
textview.setText("Error ");
}
}catch (Exception e){
e.printStackTrace();
}
}
编译构建代码
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.google.android.gms:play-services-vision:12.0.1'
implementation 'info.androidhive:barcode-reader:1.1.5'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:3.8.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
清单代码
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
<service android:name="org.eclipse.paho.android.service.MqttService" />
<activity
android:name=".loadingPage"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
爱猫
2018-10-20 23:13:27.800 1018-6418/? W/ActivityManager: Force finishing activity com.example.johnn.lodgingservicesystemowner/.QRScanner
2018-10-20 23:13:27.808 1018-3090/? E/ReportTools: This is not beta user build
2018-10-20 23:13:27.809 12122-12122/com.example.johnn.lodgingservicesystemowner I/Process: Sending signal. PID: 12122 SIG: 9
2018-10-20 23:13:27.810 746-2326/? E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
2018-10-20 23:13:27.810 746-2326/? I/chatty: uid=0(root) engine identical 1 line
2018-10-20 23:13:27.810 746-2326/? E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
2018-10-20 23:13:27.810 1847-2088/? I/ash: com.example.johnn.lodgingservicesystemowner { running duration=154915 UptimeDuration=154914 } transition to: end, reason:not_running
2018-10-20 23:13:27.810 1847-2088/? I/ash: remove app record pkg: com.example.johnn.lodgingservicesystemowner
2018-10-20 23:13:27.810 1847-2088/? I/AppManager: removeProcessDependency pid:12122
2018-10-20 23:13:27.811 746-2326/? E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
2018-10-20 23:13:27.811 746-2326/? E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
2018-10-20 23:13:27.811 746-2326/? I/iMonitor: create: 901001001
2018-10-20 23:13:27.811 746-2326/? I/iMonitor: send: 901001001
2018-10-20 23:13:27.811 746-2326/? E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.
2018-10-20 23:13:27.838 1018-6418/? V/BroadcastQueue: Finished with ordered broadcast BroadcastRecord{2eaa18a u0 android.intent.action.DROPBOX_ENTRY_ADDED}
2018-10-20 23:13:27.882 2021-3032/? D/WorkSource: Insert in WorkSource{} @ 0 uid 10015 name com.google.android.gms
2018-10-20 23:13:27.898 2021-3032/? D/WorkSource: Insert in WorkSource{} @ 0 uid 10015 name com.google.android.gms
2018-10-20 23:13:27.904 1018-1300/? W/InputDispatcher: channel '22d3b85 com.example.johnn.lodgingservicesystemowner/com.example.johnn.lodgingservicesystemowner.QRScanner (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2018-10-20 23:13:27.904 1018-1300/? E/InputDispatcher: channel '22d3b85 com.example.johnn.lodgingservicesystemowner/com.example.johnn.lodgingservicesystemowner.QRScanner (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-10-20 23:13:27.904 1018-1300/? W/InputDispatcher: channel 'da7bca1 com.example.johnn.lodgingservicesystemowner/com.example.johnn.lodgingservicesystemowner.Home (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2018-10-20 23:13:27.904 1018-1300/? E/InputDispatcher: channel 'da7bca1 com.example.johnn.lodgingservicesystemowner/com.example.johnn.lodgingservicesystemowner.Home (server)' ~ Channel is unrecoverably broken and will be disposed!
2018-10-20 23:13:27.906 1581-2091/? D/HwRecentsLockUtils: Search
2018-10-20 23:13:27.907 1778-30656/? E/HsmCoreServiceImpl: onTransact in code is: 103
2018-10-20 23:13:27.908 1778-30656/? I/MediaProcessHandler: playingUids:
2018-10-20 23:13:27.909 1018-13710/? D/ActivityManager: Skipping, home or recents stack task: TaskRecord{b246c2f #690 A=com.huawei.android.launcher U=0 StackId=0 sz=1}
2018-10-20 23:13:27.910 1018-13710/? D/ActivityManager: Skipping intent:flg=0x10804000 cmp=com.android.systemui/.recents.RecentsActivity bnds=[48,1120][1032,2362]
2018-10-20 23:13:27.910 1018-13710/? D/ActivityManager: Skipping intent:act=android.security.action.START_APP_SECURE flg=0x34808000 pkg=com.huawei.scanner cmp=com.huawei.scanner/.view.SecurityScannerActivity
2018-10-20 23:13:27.910 1018-13710/? D/ActivityManager: Skipping intent:act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10800300 cmp=com.android.settings/.FallbackHome
2018-10-20 23:13:27.921 1018-3130/? I/ActivityManager: Process com.example.johnn.lodgingservicesystemowner (pid 12122) has died: fore TOP
发生错误时,这两个消息会出现在日志中
QRScanner (server)' ~ Consumer closed input channel or an error occurred. events=0x9
.QRScanner (server)' ~ Channel is unrecoverably broken and will be disposed!