我正在为RadioPad开发一个Android应用程序:可在Android上运行的条形码扫描仪,并且在接收条形码信息时遇到问题。
问题是某些类无法从程序包外部访问。
常量的另一个问题。
我正在使用的RadioPad在Zebra MC3200
上正在Android 4.1及更高版本上工作。
我正在使用此库:barcode_scanner_library_v2.4.6.0
这是我正在处理的Main.java文件:
package com.example.zebrascanner;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.SyncStateContract.*;
import android.view.View;
import com.zebra.scannercontrol.*;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements IDcsSdkApiDelegate {
SDKHandler sdkHandler;
int scannerId;
ArrayList<DCSScannerInfo> mScannerInfoList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sdkHandler = new SDKHandler(this);
sdkHandler.dcssdkSetDelegate(this);
sdkHandler.dcssdkSetOperationalMode(DCSSDKDefs.DCSSDK_MODE.DCSSDK_OPMODE_SNAPI);
int notifications_mask = 0;
// We would like to subscribe to all scanner available/not-available events
notifications_mask |=
DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_SCANNER_APPEARANCE.value |
DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_SCANNER_DISAPPEARANCE.value;
// We would like to subscribe to all scanner connection events
notifications_mask |=
DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_SESSION_ESTABLISHMENT.value |
DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_SESSION_TERMINATION.value;
// We would like to subscribe to all barcode events
notifications_mask |= DCSSDKDefs.DCSSDK_EVENT.DCSSDK_EVENT_BARCODE.value;
// subscribe to events set in notification mask
sdkHandler.dcssdkSubsribeForEvents(notifications_mask);
// enable scanner detection
sdkHandler.dcssdkEnableAvailableScannersDetection(true);
//Synchronisation
sdkHandler.dcssdkGetAvailableScannersList(mScannerInfoList);
sdkHandler.dcssdkGetActiveScannersList(mScannerInfoList);
}
//CONNECTION TO SCANNER
public void connectToScanner(View view) {
new MyAsyncTask(scannerId).execute();
}
private class MyAsyncTask extends AsyncTask<Void, Integer, Boolean> {
private int scannerId;
public MyAsyncTask(int scannerId) {
this.scannerId = scannerId;
}
@Override
protected Boolean doInBackground(Void... voids) {
DCSSDKDefs.DCSSDK_RESULT result =
DCSSDKDefs.DCSSDK_RESULT.DCSSDK_RESULT_FAILURE;
if (sdkHandler != null) {
result =
sdkHandler.dcssdkEstablishCommunicationSession(scannerId);
}
if (result == DCSSDKDefs.DCSSDK_RESULT.DCSSDK_RESULT_SUCCESS) {
return true;
} else if (result == DCSSDKDefs.DCSSDK_RESULT.DCSSDK_RESULT_FAILURE) {
return false;
}
return false;
}
}
//RECEPTION
public class BaseActivity extends AppCompatActivity implements IDcsSdkApiDelegate {
@Override
public void dcssdkEventBarcode(byte[] barcodeData, int barcodeType, int fromScannerID) {
Barcode barcode = new Barcode(barcodeData,barcodeType,fromScannerID);
dataHandler.obtainMessage(Constants.BARCODE_RECIEVED,barcode).sendToTarget();
}
主要问题实际上在这里:
//接收
public class BaseActivity extends AppCompatActivity implements IDcsSdkApiDelegate {
@Override
public void dcssdkEventBarcode(byte[] barcodeData, int barcodeType, int fromScannerID) {
Barcode barcode = new Barcode(barcodeData,barcodeType,fromScannerID);
dataHandler.obtainMessage(Constants.BARCODE_RECIEVED,barcode).sendToTarget();
}
我希望从包中导入import com.zebra.scannercontrol.Barcode,但错误是它不是公共的,无法从包外部访问。