正式讯飞语音环境
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user