首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WinDev中的代码

WinDev中的代码
EN

Stack Overflow用户
提问于 2017-03-09 13:55:12
回答 1查看 1.2K关注 0票数 2

我是WinDev的新手,我正在尝试用条形码扫描仪在霍尼韦尔设备上创建一个安卓应用程序。我在Android中尝试了两种不同的方法,它们都能工作。其中之一是:

代码语言:javascript
复制
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.honeywell.scanintent.ScanIntent;

public class MainActivity extends Activity {
    TextView barcodeData = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        barcodeData = (TextView) findViewById(R.id.textView);
    }

    public void onSendButtonClick(View v) {
        Intent intentScan = new Intent(ScanIntent.SCAN_ACTION);
        intentScan.addCategory(Intent.CATEGORY_DEFAULT);

        intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        int loadmode = 0;

        intentScan.putExtra("scan_mode",ScanIntent.SCAN_MODE_RESULT_AS_URI);
        this.startActivityForResult(intentScan, 5);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (resultCode == ScanIntent.SCAN_RESULT_SUCCESSED) {
            String data = intent.getStringExtra(ScanIntent.EXTRA_RESULT_BARCODE_DATA);
            int format = intent.getIntExtra(ScanIntent.EXTRA_RESULT_BARCODE_FORMAT, 0);
            barcodeData.setText(data);
        }
        else{
            barcodeData.setText("FALLITO");
        }
    }
}

另一种方式是:

代码语言:javascript
复制
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.IOException;

import com.honeywell.decodemanager.DecodeManager;
import com.honeywell.decodemanager.SymbologyConfigs;
import com.honeywell.decodemanager.barcode.DecodeResult;
import com.honeywell.decodemanager.symbologyconfig.SymbologyConfigCode39;


public final class MainActivity extends Activity {

    private final int ID_SCANSETTING = 0x12;
    private final int ID_CLEAR_SCREEN = 0x13;
    private final int SCANKEY        = 0x94;
    private DecodeManager mDecodeManager = null;
    private TextView mDecodeResultEdit = null;
    private final int SCANTIMEOUT = 2000;
    long mScanAccount = 0;
    private boolean mbKeyDown = true;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button button = (Button) findViewById(R.id.button);
        mDecodeResultEdit = (TextView) findViewById(R.id.textView);
        button.setOnTouchListener(new Button.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                final int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        try {
                            if (mbKeyDown) {
                                DoScan();
                                mbKeyDown = false;
                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        try {
                            mbKeyDown = true;
                            cancleScan();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        break;
                }
                return true;
            }
        });
    }
        private void DoScan() throws Exception {
            try {
                mDecodeManager.doDecode(SCANTIMEOUT);
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    @Override
    protected void onResume() {
        super.onResume();

        if (mDecodeManager == null) {
            mDecodeManager = new DecodeManager(this ,ScanResultHandler);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();

        if (mDecodeManager != null) {
            try {
                mDecodeManager.release();
                mDecodeManager = null;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private Handler ScanResultHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case DecodeManager.MESSAGE_DECODER_COMPLETE:
                    String strDecodeResult = "";
                    DecodeResult decodeResult = (DecodeResult) msg.obj;
                    strDecodeResult = "Decode Result::"+ decodeResult.barcodeData;

                    mDecodeResultEdit.setText(strDecodeResult);
                    break;

                case DecodeManager.MESSAGE_DECODER_FAIL:
                    mDecodeResultEdit.setText("FAILED");
                    break;

                case DecodeManager.MESSAGE_DECODER_READY:
                {
                    try {
                        SymbologyConfigCode39 code39 = new SymbologyConfigCode39();
                        code39.enableCheckEnable(false);
                        code39.enableSymbology(false);
                        code39.setMaxLength(48);
                        code39.setMinLength(2);

                        SymbologyConfigs symconfig = new SymbologyConfigs();

                        symconfig.addSymbologyConfig(code39);
                        mDecodeManager.setSymbologyConfigs(symconfig);

                    } catch (RemoteException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                    break;

                default:
                    super.handleMessage(msg);
                    break;
            }
        }
    };

    private void cancleScan() throws Exception {
        mDecodeManager.cancelDecode();
    }
}

在WinDev上,我创建了一个全局JAVA过程,并生成了这个应用程序,导入了honeywell库,但是我不知道如何实现android本机函数。我该怎么做?

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2017-06-06 14:55:48

首先向项目添加全局过程集,然后在此集合中创建一个空的全局过程。

一旦在头栏上创建了这个过程,点击字母,WL,,它就会转换成JAVA代码模式。现在粘贴JAVA代码!

HTH

杨耀基

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42697231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档