urovosamples / SDK_ReleaseforAndroid

This repository contains all the samples files for Urovo Android Smart POS Payment Terminal;Handheld Data Terminal, including the revision history.
53 stars 25 forks source link

Cant register broadcast for scanner #16

Closed sOlnblshkO closed 2 years ago

sOlnblshkO commented 2 years ago

Hello! I`m using UROVO DT40 and trying to use integrated scanner. So after this some searchs found only this repo. After some look on ScanManager Sample found that you register broadcast to get result after result, but cant find realise for register(unregister) broadcast. Because there is no reference on this method. IDE found problem that there is not function with this parameters, but if build and run app - everything is fine. PROBLEM: Cant understand how to register broadcast reciver for scanned code.

private void registerReceiver(boolean register) {
        if (register && mScanManager != null) {
            IntentFilter filter = new IntentFilter();
            int[] idbuf = new int[]{PropertyID.WEDGE_INTENT_ACTION_NAME, PropertyID.WEDGE_INTENT_DATA_STRING_TAG};
            String[] value_buf = mScanManager.getParameterString(idbuf);
            if (value_buf != null && value_buf[0] != null && !value_buf[0].equals("")) {
                filter.addAction(value_buf[0]);
            } else {
                filter.addAction(ACTION_DECODE);
            }
            filter.addAction(ACTION_CAPTURE_IMAGE);

            registerReceiver(mReceiver, filter); // <- THIS ONE
        } else if (mScanManager != null) {
            mScanManager.stopDecode();
            unregisterReceiver(mReceiver); // <- AND THIS 
        }
    }
sOlnblshkO commented 2 years ago

So, after some more research, i found that you created all this code in AppCompatActivity which has Context. And context can registerReciever. Issue closed