2017-03-09 64 views
2

我是WinDev中的新成員,我試圖在帶有條形碼掃描器的honeywell設備上創建一個Android應用程序。 我在Android Studio中嘗試了兩種不同的方式,他們工作。 是下列其中一項:WinDev中的Java Android代碼

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"); 
     } 
    } 
} 

而另一種方式是這樣的:

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程序,我產生的應用程序,導入霍尼韋爾庫,但我不瞭解如何實現Android本機功能。我怎樣才能做到這一點?

非常感謝!

回答

0

首先爲您的項目添加一個全局過程集,然後在此集中創建一個空的全局過程。

一旦程序在其標題欄上創建,點擊字母WL,它將轉換爲JAVA代碼模式。現在貼你的JAVA代碼!

HTH

瑜珈楊