正式讯飞语音环境
This commit is contained in:
@ -61,6 +61,7 @@ android {
|
||||
}*/
|
||||
}
|
||||
dependencies {
|
||||
compileOnly 'com.symbol:emdk:+'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'com.google.code.gson:gson:2.6.2'
|
||||
|
||||
BIN
app/libs/DataCollection.jar
Normal file
BIN
app/libs/DataCollection.jar
Normal file
Binary file not shown.
@ -10,6 +10,7 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="com.symbol.emdk.permission.EMDK"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -23,6 +24,7 @@
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:screenOrientation="user"
|
||||
>
|
||||
<uses-library android:name="com.symbol.emdk"/>
|
||||
<activity
|
||||
android:name=".activity.NetworkSettingActivity"
|
||||
android:label="@string/title_activity_setting_network" />
|
||||
@ -38,6 +40,17 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service android:name=".service.ScanServiceEDA50P">
|
||||
<intent-filter>
|
||||
<action android:name="com.example.chaoran.ScanServiceEDA50P"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service android:name=".service.ScanServiceZEBRA">
|
||||
<intent-filter>
|
||||
<action android:name="com.example.chaoran.ScanServiceZEBRA"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -35,6 +35,8 @@ import chaoran.business.engine.impl.NetworkSettingEngine;
|
||||
import chaoran.business.engine.SettingEngine;
|
||||
import chaoran.business.engine.impl.TekVoiceEngine;
|
||||
import chaoran.business.engine.VoiceEngine;
|
||||
import chaoran.business.service.ScanServiceEDA50P;
|
||||
import chaoran.business.service.ScanServiceZEBRA;
|
||||
import chaoran.business.utils.LocalAddressUtil;
|
||||
import chaoran.business.utils.StatusBarUtil;
|
||||
|
||||
@ -54,7 +56,6 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
private ProgressBar progressBar;
|
||||
private ActionBar actionBar;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -72,7 +73,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
BrandEnum brand = BrandEnum.code(Build.MANUFACTURER);
|
||||
Toast.makeText(this, Build.MANUFACTURER, Toast.LENGTH_LONG).show();
|
||||
Log.i("brand===",brand.toString());
|
||||
/* switch (brand) {
|
||||
switch (brand) {
|
||||
case UROBO:
|
||||
adapter = new UroBoAdapter(this, this);
|
||||
break;
|
||||
@ -88,7 +89,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
}
|
||||
if (null != adapter) {
|
||||
adapter.start();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@SuppressLint("JavascriptInterface")
|
||||
private void initView() {
|
||||
@ -195,7 +196,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
}
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// adapter.stop();
|
||||
adapter.stop();
|
||||
super.onDestroy();
|
||||
if (diPlayer != null) {
|
||||
diPlayer.stop();
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
package chaoran.business.adapter;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
|
||||
import chaoran.business.activity.MainActivity;
|
||||
import chaoran.business.activity.ResultListener;
|
||||
import chaoran.business.service.ScanServiceEDA50P;
|
||||
import chaoran.business.service.ScanServiceZEBRA;
|
||||
import chaoran.business.strategy.Strategy;
|
||||
|
||||
|
||||
public class HoneywellAdapter implements Adapter {
|
||||
private Context context;
|
||||
private Strategy strategy;
|
||||
private ResultListener resultListener;
|
||||
private Intent intent = null;
|
||||
|
||||
public HoneywellAdapter(Context context, ResultListener resultListener) {
|
||||
this.context = context;
|
||||
this.resultListener = resultListener;
|
||||
strategy = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
strategy.executeStrategy(resultListener);
|
||||
openContinueScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
strategy.exclusiveStrategy();
|
||||
}
|
||||
|
||||
public class Receiver extends BroadcastReceiver implements Strategy {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
resultListener.result(intent.getStringExtra("data"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStrategy(ResultListener resultListener) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.honeywell.scan.broadcast");
|
||||
context.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exclusiveStrategy() {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
public void openContinueScan(){
|
||||
if("eda50p".equals(Build.MODEL.toLowerCase())){
|
||||
intent = new Intent(context, ScanServiceEDA50P.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.getApplicationContext().startForegroundService(intent);
|
||||
}else {
|
||||
context.getApplicationContext().startService(intent);
|
||||
}
|
||||
}else if("tc26".equals(Build.MODEL.toLowerCase())){
|
||||
intent = new Intent(context, ScanServiceZEBRA.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.getApplicationContext().startForegroundService(intent);
|
||||
}else {
|
||||
context.getApplicationContext().startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
package chaoran.business.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.honeywell.aidc.AidcManager;
|
||||
import com.honeywell.aidc.BarcodeDeviceConnectionEvent;
|
||||
import com.honeywell.aidc.BarcodeFailureEvent;
|
||||
import com.honeywell.aidc.BarcodeReadEvent;
|
||||
import com.honeywell.aidc.BarcodeReader;
|
||||
import com.honeywell.aidc.BarcodeReaderInfo;
|
||||
import com.honeywell.aidc.ScannerNotClaimedException;
|
||||
import com.honeywell.aidc.ScannerUnavailableException;
|
||||
import com.honeywell.aidc.TriggerStateChangeEvent;
|
||||
import com.honeywell.aidc.UnsupportedPropertyException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
public class ScanServiceEDA50P extends Service
|
||||
implements BarcodeReader.BarcodeListener, BarcodeReader.TriggerListener, AidcManager.BarcodeDeviceListener{
|
||||
private final String TAG = "TestScanService";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private String notificationId = "channelId";
|
||||
private String notificationName = "channelName";
|
||||
|
||||
private String _Suffix = "\n";
|
||||
|
||||
|
||||
private AidcManager mAidcManager;
|
||||
private BarcodeReader mBarcodeReader;
|
||||
private BarcodeReader mInternalScannerReader;
|
||||
private boolean mKeyPressed = false;
|
||||
private boolean isContinue = true;
|
||||
|
||||
//必须要实现的方法
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// Log.i(TAG, "onBind方法被调用!");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被创建时调用
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Log.i(TAG, "onCreate方法被调用!");
|
||||
super.onCreate();
|
||||
super.onCreate();
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //适配8.0service
|
||||
channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build();
|
||||
//startForeground(1,getNotification());
|
||||
startForeground(1, notification);
|
||||
}
|
||||
|
||||
AidcManager.create(this, new MyCreatedCallback());
|
||||
}
|
||||
|
||||
//Service被启动时调用
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i(TAG, "onStartCommand方法被调用!");
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
//Service被关闭之前回调
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.i(TAG, "onDestory方法被调用!");
|
||||
super.onDestroy();
|
||||
|
||||
if (this.mInternalScannerReader != null) {
|
||||
this.mInternalScannerReader.removeBarcodeListener(this);
|
||||
this.mInternalScannerReader.removeTriggerListener(this);
|
||||
this.mInternalScannerReader.close();
|
||||
this.mInternalScannerReader = null;
|
||||
Log.d(TAG, "Close internal scanner");
|
||||
}
|
||||
if (this.mAidcManager != null) {
|
||||
this.mAidcManager.removeBarcodeDeviceListener(this);
|
||||
this.mAidcManager.close();
|
||||
}
|
||||
|
||||
}
|
||||
class MyCreatedCallback implements AidcManager.CreatedCallback {
|
||||
MyCreatedCallback() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(AidcManager aidcManager) {
|
||||
Log.d(TAG, "MyCreatedCallback onCreate !!!");
|
||||
mAidcManager = aidcManager;
|
||||
mAidcManager.addBarcodeDeviceListener(ScanServiceEDA50P.this);
|
||||
initAllBarcodeReaderAndSetDefault();
|
||||
}
|
||||
}
|
||||
void initAllBarcodeReaderAndSetDefault() {
|
||||
List<BarcodeReaderInfo> readerList = mAidcManager.listBarcodeDevices();
|
||||
Log.d(TAG, "initAllBarcodeReaderAndSetDefault readerList = "+readerList);
|
||||
mInternalScannerReader = null;
|
||||
for (BarcodeReaderInfo reader : readerList) {
|
||||
if ("dcs.scanner.imager".equals(reader.getName())) {
|
||||
mInternalScannerReader = initBarcodeReader(mInternalScannerReader, reader.getName());
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "initAllBarcodeReaderAndSetDefault mInternalScannerReader = "+mInternalScannerReader);
|
||||
|
||||
if (mInternalScannerReader != null) {
|
||||
mBarcodeReader = mInternalScannerReader;
|
||||
}
|
||||
else {
|
||||
Log.d(TAG, "No reader find");
|
||||
}
|
||||
if (mBarcodeReader != null) {
|
||||
try {
|
||||
mBarcodeReader.addBarcodeListener(this);
|
||||
mBarcodeReader.addTriggerListener(this);
|
||||
}
|
||||
catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mBarcodeReader.setProperty(BarcodeReader.PROPERTY_NOTIFICATION_GOOD_READ_ENABLED, true);
|
||||
mBarcodeReader.setProperty(BarcodeReader.PROPERTY_EAN_13_CHECK_DIGIT_TRANSMIT_ENABLED, true);
|
||||
|
||||
} catch (UnsupportedPropertyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BarcodeReader initBarcodeReader(BarcodeReader mReader, String mReaderName) {
|
||||
if (mReader == null) {
|
||||
try {
|
||||
if (mReaderName == null) {
|
||||
mReader = mAidcManager.createBarcodeReader();
|
||||
} else {
|
||||
mReader = mAidcManager.createBarcodeReader(mReaderName);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e(TAG, "error", e);
|
||||
}
|
||||
try {
|
||||
mReader.claim();
|
||||
Log.d(TAG, "Call DCS interface claim() " + mReaderName);
|
||||
} catch (ScannerUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL);
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_DATA_PROCESSOR_LAUNCH_EZ_CONFIG, false);
|
||||
mReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_AUTO_MODE_TIMEOUT, 300);
|
||||
|
||||
} catch (UnsupportedPropertyException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mReader;
|
||||
}
|
||||
|
||||
public void onBarcodeDeviceConnectionEvent(BarcodeDeviceConnectionEvent event) {
|
||||
Log.d(TAG, event.getBarcodeReaderInfo() + " Connection status: " + event.getConnectionStatus());
|
||||
}
|
||||
|
||||
public void onBarcodeEvent(final BarcodeReadEvent event) {
|
||||
String barcodeDate = new String(event.getBarcodeData().getBytes(event.getCharset()));
|
||||
Intent intent2 = new Intent("com.pda.scan.result");
|
||||
intent2.putExtra("data",barcodeDate);
|
||||
sendBroadcast(intent2);
|
||||
if(isContinue) {
|
||||
executorService.execute(new MyThread(mBarcodeReader));
|
||||
}
|
||||
}
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
class MyThread implements Runnable{
|
||||
private BarcodeReader mBarcodeReader;
|
||||
public MyThread(BarcodeReader mBarcodeReader){
|
||||
this.mBarcodeReader = mBarcodeReader;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
{
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
mBarcodeReader.decode(true);
|
||||
} catch (ScannerNotClaimedException e) {
|
||||
Log.e(TAG, "catch ScannerNotClaimedException",e);
|
||||
e.printStackTrace();
|
||||
} catch (ScannerUnavailableException e2) {
|
||||
Log.e(TAG, "catch ScannerUnavailableException",e2);
|
||||
e2.printStackTrace();
|
||||
} catch (Exception e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onFailureEvent(final BarcodeFailureEvent event) {
|
||||
//Log.d(TAG, "Enter onFailureEvent ===> " + event.getTimestamp());
|
||||
if(isContinue) {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// doScan(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onTriggerEvent(TriggerStateChangeEvent event) {
|
||||
if (event.getState()) {
|
||||
if (!mKeyPressed) {
|
||||
mKeyPressed = true;
|
||||
doScan(true);
|
||||
}else{
|
||||
mKeyPressed = false;
|
||||
doScan(false);
|
||||
}
|
||||
} else {
|
||||
//mKeyPressed = false;
|
||||
// doScan(false);
|
||||
}
|
||||
// Log.d(TAG, "OnTriggerEvent status: " + event.getState());
|
||||
}
|
||||
void doScan(boolean do_scan) {
|
||||
try {
|
||||
if (do_scan) {
|
||||
// Log.d(TAG, "Start a new Scan!");
|
||||
} else {
|
||||
// Log.d(TAG, "Cancel last Scan!");
|
||||
}
|
||||
mBarcodeReader.decode(do_scan);
|
||||
} catch (ScannerNotClaimedException e) {
|
||||
Log.e(TAG, "catch ScannerNotClaimedException",e);
|
||||
e.printStackTrace();
|
||||
} catch (ScannerUnavailableException e2) {
|
||||
Log.e(TAG, "catch ScannerUnavailableException",e2);
|
||||
e2.printStackTrace();
|
||||
} catch (Exception e3) {
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
333
app/src/main/java/chaoran/business/service/ScanServiceZEBRA.java
Normal file
333
app/src/main/java/chaoran/business/service/ScanServiceZEBRA.java
Normal file
@ -0,0 +1,333 @@
|
||||
package chaoran.business.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.symbol.emdk.EMDKManager;
|
||||
import com.symbol.emdk.EMDKResults;
|
||||
import com.symbol.emdk.barcode.BarcodeManager;
|
||||
import com.symbol.emdk.barcode.ScanDataCollection;
|
||||
import com.symbol.emdk.barcode.Scanner;
|
||||
import com.symbol.emdk.barcode.ScannerConfig;
|
||||
import com.symbol.emdk.barcode.ScannerException;
|
||||
import com.symbol.emdk.barcode.ScannerResults;
|
||||
import com.symbol.emdk.barcode.StatusData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ScanServiceZEBRA extends Service implements EMDKManager.EMDKListener, Scanner.DataListener, Scanner.StatusListener {
|
||||
private final String TAG = "ScanService";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private String notificationId = "ScanServiceId";
|
||||
private String notificationName = "ScanServiceName";
|
||||
|
||||
private EMDKManager emdkManager = null;
|
||||
private BarcodeManager barcodeManager = null;
|
||||
private Scanner scanner = null;
|
||||
|
||||
private String statusString = "";
|
||||
|
||||
private boolean bSoftTriggerSelected = true;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
Log.i(TAG, "onBind方法被调用!");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被创建时调用
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i(TAG, "onCreate方法被调用!");
|
||||
super.onCreate();
|
||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //适配8.0service
|
||||
channel = new NotificationChannel(notificationId, notificationName, NotificationManager.IMPORTANCE_HIGH);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
Notification notification = new Notification.Builder(getApplicationContext(), notificationId).build();
|
||||
//startForeground(1,getNotification());
|
||||
startForeground(1, notification);
|
||||
}
|
||||
EMDKResults results = EMDKManager.getEMDKManager(getApplicationContext(), this);
|
||||
final IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("com.pda.scan.trigger");
|
||||
registerReceiver(myCodeReceiver, intentFilter);
|
||||
}
|
||||
private MyCodeReceiver myCodeReceiver = new MyCodeReceiver();
|
||||
|
||||
public class MyCodeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int keyCode = intent.getIntExtra("data",0);
|
||||
if(keyCode == 103 || keyCode == 10036){
|
||||
if(bSoftTriggerSelected){
|
||||
bSoftTriggerSelected = false;
|
||||
}else{
|
||||
bSoftTriggerSelected = true;
|
||||
cancelRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* private Notification getNotification() {
|
||||
Notification.Builder builder = new Notification.Builder(this)
|
||||
.setContentTitle("连续扫描服务")
|
||||
.setContentText("正在运行");
|
||||
builder.setChannelId(notificationId);
|
||||
Notification notification = builder.build();
|
||||
return notification;
|
||||
}*/
|
||||
|
||||
//Service被启动时调用
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.i(TAG, "onStartCommand方法被调用!");
|
||||
|
||||
//setconfig();
|
||||
initScanner();
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
public void setconfig(){
|
||||
Intent i = new Intent();
|
||||
i.setAction("com.symbol.datawedge.api.ACTION");
|
||||
i.putExtra("com.symbol.datawedge.api.SET_DEFAULT_PROFILE", "myProfile");
|
||||
sendBroadcast(i);
|
||||
}
|
||||
@Override
|
||||
public void onOpened(EMDKManager emdkManager) {
|
||||
updateStatus("EMDK open success!");
|
||||
this.emdkManager = emdkManager;
|
||||
// Acquire the barcode manager resources
|
||||
initBarcodeManager();
|
||||
// Enumerate scanner devices
|
||||
// enumerateScannerDevices();
|
||||
initScanner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed() {
|
||||
// Release all the resources
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release();
|
||||
emdkManager = null;
|
||||
}
|
||||
updateStatus("EMDK closed unexpectedly! Please close and restart the application.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Release all the resources
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release();
|
||||
emdkManager = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onData(ScanDataCollection scanDataCollection) {
|
||||
if ((scanDataCollection != null) && (scanDataCollection.getResult() == ScannerResults.SUCCESS)) {
|
||||
ArrayList<ScanDataCollection.ScanData> scanData = scanDataCollection.getScanData();
|
||||
for (ScanDataCollection.ScanData data : scanData) {
|
||||
updateData(data.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatus(StatusData statusData) {
|
||||
StatusData.ScannerStates state = statusData.getState();
|
||||
switch (state) {
|
||||
case IDLE:
|
||||
statusString = statusData.getFriendlyName() + " is enabled and idle...";
|
||||
updateStatus(statusString);
|
||||
// set trigger type
|
||||
if(bSoftTriggerSelected) {
|
||||
scanner.triggerType = Scanner.TriggerType.SOFT_ALWAYS;
|
||||
setDecoders();
|
||||
} else {
|
||||
scanner.triggerType = Scanner.TriggerType.HARD;
|
||||
cancelRead();
|
||||
}
|
||||
// submit read
|
||||
if (!scanner.isReadPending()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Log.i("jqtest:", "scan");
|
||||
scanner.read();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
updateStatus(e.getMessage());
|
||||
try {
|
||||
deInitScanner();
|
||||
Thread.sleep(200);
|
||||
}catch (Exception e1){
|
||||
e1.printStackTrace();
|
||||
}
|
||||
initScanner();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WAITING:
|
||||
statusString = "Scanner is waiting for trigger press...";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case SCANNING:
|
||||
statusString = "Scanning...";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case DISABLED:
|
||||
statusString = statusData.getFriendlyName() + " is disabled.";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
case ERROR:
|
||||
statusString = "An error has occurred.";
|
||||
updateStatus(statusString);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void initScanner() {
|
||||
if (scanner == null) {
|
||||
if (barcodeManager != null) {
|
||||
scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);
|
||||
} else {
|
||||
updateStatus("Failed to get the specified scanner device! Please close and restart the application.");
|
||||
return;
|
||||
}
|
||||
if (scanner != null) {
|
||||
scanner.addDataListener(this);
|
||||
scanner.addStatusListener(this);
|
||||
try {
|
||||
scanner.enable();
|
||||
} catch (ScannerException e) {
|
||||
updateStatus(e.getMessage());
|
||||
deInitScanner();
|
||||
}
|
||||
} else {
|
||||
updateStatus("Failed to initialize the scanner device.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deInitScanner() {
|
||||
if (scanner != null) {
|
||||
try {
|
||||
scanner.disable();
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
scanner.removeDataListener(this);
|
||||
scanner.removeStatusListener(this);
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
scanner.release();
|
||||
} catch (Exception e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
scanner = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initBarcodeManager() {
|
||||
barcodeManager = (BarcodeManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.BARCODE);
|
||||
|
||||
}
|
||||
|
||||
private void deInitBarcodeManager() {
|
||||
if (emdkManager != null) {
|
||||
emdkManager.release(EMDKManager.FEATURE_TYPE.BARCODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* private void enumerateScannerDevices() {
|
||||
if (barcodeManager != null) {
|
||||
List<ScannerInfo> deviceList = barcodeManager.getSupportedDevicesInfo();
|
||||
if ((deviceList != null) && (deviceList.size() != 0)) {
|
||||
Iterator<ScannerInfo> it = deviceList.iterator();
|
||||
while (it.hasNext()) {
|
||||
ScannerInfo scnInfo = it.next();
|
||||
if (scnInfo.isDefaultScanner()) {
|
||||
scannerInfo = scnInfo;
|
||||
Log.i("scannerInfo", scannerInfo.getFriendlyName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private void setDecoders() {
|
||||
if (scanner != null) {
|
||||
try {
|
||||
ScannerConfig config = scanner.getConfig();
|
||||
// Set EAN8
|
||||
config.decoderParams.ean8.enabled = true;
|
||||
// Set EAN13
|
||||
config.decoderParams.ean13.enabled = true;
|
||||
// Set Code39
|
||||
config.decoderParams.code39.enabled = true;
|
||||
//Set Code128
|
||||
config.decoderParams.code128.enabled = true;
|
||||
// config.readerParams.readerSpecific.imagerSpecific.aimType = ScannerConfig.AimType.PRESENTATION;
|
||||
scanner.setConfig(config);
|
||||
} catch (ScannerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelRead() {
|
||||
if (scanner != null) {
|
||||
if (scanner.isReadPending()) {
|
||||
try {
|
||||
scanner.cancelRead();
|
||||
} catch (ScannerException e) {
|
||||
updateStatus(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatus(final String status) {
|
||||
//Log.i("status",status);
|
||||
// runOnUiThread(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// textViewStatus.setText("" + status);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void updateData(final String result) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
Intent intent2 = new Intent("com.pda.scan.result");
|
||||
intent2.putExtra("data", result);
|
||||
sendBroadcast(intent2);
|
||||
Log.i(TAG, result);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user