Dag,
het volgende 'probleem'/vraagstuk heb ik,
Hoe is het in phonegap (android) mogelijk om naar device keycode 92 te luisteren, dit is een scan knop op een Cilico CM380. Dit gebruik ik om barcodes te scannen. Daarintegen is het al wel mogelijk om in de eclipse logcat de gescande barcode weer te laten geven zodra die gescand is, alleen komt deze niet verder naar phonegap omdat deze niet
'luistert' na het activeren van de barcode laser.
UPDATE
Problem solved door de scanCode vanuit javascript aan te roepen die word aangeroepen in start.java onCreate
Onderstaand de files die ik hiervoor nu gebruik
het volgende 'probleem'/vraagstuk heb ik,
Hoe is het in phonegap (android) mogelijk om naar device keycode 92 te luisteren, dit is een scan knop op een Cilico CM380. Dit gebruik ik om barcodes te scannen. Daarintegen is het al wel mogelijk om in de eclipse logcat de gescande barcode weer te laten geven zodra die gescand is, alleen komt deze niet verder naar phonegap omdat deze niet
'luistert' na het activeren van de barcode laser.
UPDATE
Problem solved door de scanCode vanuit javascript aan te roepen die word aangeroepen in start.java onCreate
Onderstaand de files die ik hiervoor nu gebruik
Java: Barcode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| package com.phonegap.plugin.barcode; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult.Status; import android.util.Log; public class Barcode extends Plugin { public static final String READ = "read"; public static final String ME = "logging"; public static String callback; public PluginResult result; @Override public PluginResult execute(String action, JSONArray data, String callbackId){ Log.d(ME, "execute " + action); if (action.equalsIgnoreCase(READ)) { return new PluginResult(Status.OK,data); } return new PluginResult(Status.NO_RESULT); } public static void sendJavascript( JSONObject data ) { Log.v(ME,data.toString()); new PluginResult(PluginResult.Status.OK,data); } } |
JavaScript: barcode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| /** * * @return Instance of Barcode */ var Barcode = function() {} Barcode.prototype.read = function( successCallback, failureCallback ) { return cordova.exec(successCallback,failureCallback,'Barcode','read'); }; if(!window.plugins) { window.plugins = {}; } if (!window.plugins.Barcode) { window.plugins.Barcode = new Barcode(); } |
Java: Scanner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
| package cilico.tools.barcode; import java.io.IOException; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioTrack; import android.os.Handler; import android.os.Message; import android.util.Log; import android.widget.Toast; public class Scanner { static public final int BARCODE_READ= 10; static public final int BARCODE_NOREAD = 12; static Boolean m_bASYC=false; static int m_nCommand=0; static public Handler m_handler=null; /** * ??????h?????????????h?????H?????????????????3?? * ????????????????10?????????????????????????H???????????? * @return ??????????????????û??????????? */ static public native String ReadSCAAuto(); /** * ??????h?????????????h?????H?????????????????3?? * ????????????????10?? * @param nCode ??????????????????????0x55,H??????????0x00 * @return ??????????????????û??????????? */ static public native String ReadSCA(int nCode); /** * ??'???? * * @return ?????????0 */ static public native int InitSCA(); /** * ????????øú??????h???????????? * ?????????????????????handle??????????????? * ????'???????L?????????L????????????handle, * ????handle????m_handler???????????Message BARCODE_READ?? * ???????Message BARCODE_NOREAD */ static public void Read() { if(m_bASYC) { return; } else { //m_nCommand=nCode; StartASYC(); } } /** * ?????? */ static void StartASYC() { m_bASYC=true; Thread thread = new Thread(new Runnable() { public void run() { if(m_handler!=null) { String str=ReadSCAAuto(); Message msg=new Message(); msg.what=str.length()>0?BARCODE_READ:BARCODE_NOREAD; msg.obj=str; m_handler.sendMessage(msg); } m_bASYC=false; } }); thread.start(); } /** * ?????????????????String??????????????????? * @param str ??????????? */ static public void SendString(String str) { try { Runtime.getRuntime().exec("input keyevent 66"); Runtime.getRuntime().exec("input text "+str); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.i("run",e.toString()); } } static private void showToast(String str){ Toast.makeText(null, str, Toast.LENGTH_SHORT).show();} static{ //System.loadLibrary("Cilico-Scan"); System.loadLibrary("tiny-tools"); } } |
Java: Start.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| package com.start; import org.apache.cordova.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.util.Log; import android.view.KeyEvent; import android.view.WindowManager; import cilico.tools.barcode.*; import com.phonegap.plugin.barcode.Barcode; public class start extends DroidGap { private Handler mHandler = new MainHandler(); public static final String ME="start"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.setIntegerProperty("splashscreen", R.drawable.ic_splash); super.loadUrl("file:///android_asset/www/index.html", 10000); Scanner.Read(); } private class MainHandler extends Handler { @Override public void handleMessage(Message msg) { JSONObject json; switch (msg.what) { case Scanner.BARCODE_READ: { try{ json = new JSONObject(); json.put("code", msg.obj.toString()); Log.v(ME,(String) msg.obj.toString()); Barcode.sendJavascript( json ); }catch( JSONException e){} break; } case Scanner.BARCODE_NOREAD:{ break; } default: break; } } } protected void onStart() { Scanner.m_handler=mHandler; Scanner.InitSCA(); super.onStart(); } public boolean onKeyDown(int keyCode, KeyEvent event){ if(event.getRepeatCount()==0){ if(keyCode==4){ finish(); }else if((keyCode==92)){ Scanner.Read(); } } return true; } } |
[ Voor 82% gewijzigd door nettob op 08-12-2012 17:24 ]