I'm struggling with this issue. How I can call key event from another java class (keyboard.java) to run activity in this codereader.java class
I detect the key on keyboard.java by this
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
playClick(primaryCode);
switch (primaryCode) {
case -101:
//do something with the key -101
break;
And I need to call it here and run activity in codereader.java
public class QRscanner extends Activity implements ZXingScannerView.ResultHandler{
private ZXingScannerView mScannerView;
@Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick (View v){
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
I have try codereader by it own and works perfectly when I call onCLick from activity_main.xml button.
You can send an event via EventBus: https://github.com/greenrobot/EventBus