Я работаю над приложением для сканера Zebra Technologies TC8000, использующим DataWedge.Я использую Android Studio 3.5 и флаттер для мобильного фреймворка.
Я использую Broadcast Receiver в своей основной деятельности и пытаюсь использовать обратный вызов в своем коде Dart.
Когда яНажмите на курок на сканере, я вижу следующее в logcat:
04-22 11:35:12.946 1009-1009/? D/ScannerPlugin: Scan status changed from SCAN_STATUS_WAITFORTRIGGER to SCAN_STATUS_SCANNING
04-22 11:35:12.946 1009-1009/? D/Client: requested to send: 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.956 1009-1009/? D/Client: sent: 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.956 1009-1009/? D/ScannerPlugin: Status:SCANNING;ProfileName:Profile0 (default)
04-22 11:35:12.956 1009-1009/? D/ScannerStateChanged: deserialize: state: SCAN_STATUS_SCANNING
04-22 11:35:12.966 1009-1009/? D/Protocol: parsed 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.966 1009-1009/? D/SwipeAssistService: handleMessage(110 (ScannerStateChanged): SCAN_STATUS_SCANNING), connected clients: 1
04-22 11:35:13.416 665-665/? E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=com.symbol.datawedge/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x11 kind=[null])
04-22 11:35:13.416 665-665/? E/NotificationService: WARNING: In a future release this will crash the app: com.symbol.datawedge
04-22 11:35:13.436 1009-1009/? D/ScannerPlugin: Scan status changed from SCAN_STATUS_SCANNING to SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Client: requested to send: 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Client: sent: 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/ScannerPlugin: Status:WAITING;ProfileName:Profile0 (default)
04-22 11:35:13.436 1009-1009/? D/ScannerStateChanged: deserialize: state: SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Protocol: parsed 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/SwipeAssistService: handleMessage(110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER), connected clients: 1
Сканирующий луч включается, и сканер подтверждает считывание штрих-кода, но я не получаю событие.Я обеспокоен линией:
04-22 11:35:13.416 665-665/? E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=com.symbol.datawedge/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x11 kind=[null])
Я проверил документы Zebra и изменил свой код, чтобы зарегистрировать приемник вещания.Вот мой код MainActivity:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import com.goodyear.flutter_plugin.R;
import static android.content.ContentValues.TAG;
public class MainActivity extends FlutterActivity {
private static String INTENT_ACTION;
private static String SCAN_DATA;
private static String CHANNEL;
private static String METHOD;
private static String NOTIFICATION_ACTION;
private static String NOTIFICATION_TYPE_SCANNER_STATUS;
private Result barcodeResult;
private void registerReceivers() {
IntentFilter filter = new IntentFilter();
filter.addAction(NOTIFICATION_ACTION);
registerReceiver(broadcastReceiver, filter);
}
private void unRegisterReceivers() {
unregisterReceiver(broadcastReceiver);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("Barcode", "Inside onCreate");
super.onCreate(savedInstanceState);
INTENT_ACTION = getResources().getString(R.string.activity_intent_filter_action);
SCAN_DATA = getResources().getString(R.string.datawedge_intent_key_data);
CHANNEL = getResources().getString(R.string.barcode_method_channel);
METHOD = getResources().getString(R.string.barcode_method);
NOTIFICATION_ACTION = getResources().getString(R.string.datawedge_notification_action);
NOTIFICATION_TYPE_SCANNER_STATUS = getResources().getString(R.string.datawedge_notification_scanner_status);
registerReceivers();
Bundle b = new Bundle();
b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "SCANNER_STATUS");
Intent i = new Intent();
i.setAction("com.symbol.datawedge.api.ACTION");
i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b);//(1)
this.sendBroadcast(i);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
Log.i("Barcode", "Inside onMethodCall");
if (call.method.equals(METHOD)) {
Log.i("Barcode", "Result = " + result);
barcodeResult = result;
}
Log.i("Barcode", "Leaving onMethodCall");
}
}
);
Log.i("Barcode", "Leaving onCreate");
}
@Override
protected void onDestroy() {
unRegisterReceivers();
super.onDestroy();
}
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Barcode", "Inside onReceive");
String action = intent.getAction();
Log.d("Barcode", "#DataWedge-APP# Action: " + action);
switch (action) {
case "com.symbol.datawedge.api.NOTIFICATION_ACTION":
logStatus(intent);
break;
case "com.com.goodyear.ACTION":
readScanData(intent);
break;
}
}
};
private void logStatus(Intent intent) {
if (intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION")) {
Bundle b = intent.getBundleExtra("com.symbol.datawedge.api.NOTIFICATION");
String NOTIFICATION_TYPE = b.getString("NOTIFICATION_TYPE");
if (NOTIFICATION_TYPE != null) {
Log.d("Barcode", "SCANNER_STATUS: status: " + b.getString("STATUS") + ", profileName: " + b.getString("PROFILE_NAME"));
}
}
}
private void readScanData(Intent intent) {
String barCode = intent.getStringExtra(SCAN_DATA);
// String decodedLabelType = intent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_label_type));
try {
Log.i("Barcode", "Barcode = " + barCode);
barcodeResult.success(barCode);
} catch (Exception e) {
// Catch if the UI does not exist when we receive the broadcast
}
Log.i("Barcode", "Leaving onReceive");
}
}
Это расстраивает.Кажется, проблема не в моем коде, поскольку я установил точки останова в событии onReceive()
, и этот метод не срабатывает.
Не уверен, в чем проблема.