获得摩托罗拉TC55的扫描价值

mbu*_*urm 2 android motorola barcode-scanner android-intent android-broadcast

我想在我的应用程序中扫描条形码.我可以开始扫描,但我不知道如何检测扫描值.我的代码看起来像

public class MyFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.pick, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // scan
        this.getActivity().findViewById(R.id.scan).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                // Start the scanner like in the example:  https://developer.motorolasolutions.com/docs/DOC-1874#PROGRAMMING%20INTERFACE                    Intent intent = new Intent();
                intent.setAction("com.motorolasolutions.emdk.datawedge.api.ACTION_SOFTSCANTRIGGER");
                intent.putExtra("com.motorolasolutions.emdk.datawedge.api.EXTRA_PARAMETER", "TOGGLE_SCANNING");
                view.getContext().sendOrderedBroadcast(intent, null, receiver, null, 0, null, null);
            }
        });
    }

    private BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // How to detect the scanned value???       
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

mbu*_*urm 8

我可以解决它.这是代码.

Intent intent = new Intent();
intent.setAction("com.motorolasolutions.emdk.datawedge.api.ACTION_SOFTSCANTRIGGER");
intent.putExtra("com.motorolasolutions.emdk.datawedge.api.EXTRA_PARAMETER", "TOGGLE_SCANNING");
getActivity().sendBroadcast(intent);

getActivity().registerReceiver(new BroadcastReceiver() {

    @Override        
    public void onReceive(Context context, Intent intent) {                
        String code = intent.getExtras().getString("com.motorolasolutions.emdk.datawedge.data_string");

        // do something

        getActivity().unregisterReceiver(this);
    }
}
, new IntentFilter("MyIntentAction"));
Run Code Online (Sandbox Code Playgroud)

在配置文件DataWedge必须使通过意图输出和禁用按键输出.意图动作是设置一个String与之相同的"MyIntentAction".然后我在扫描后直接在我的片段中获得扫描的条形码.