Android : Prevent "Complete Action Using" dialog from appearing after pressing on Android search button

on Monday, October 13, 2014


I have created a Phonegap application for an embedded device, and created a plugin to invoke the device scanner when the user presses the hardware search button.


When the device successfully decodes a barcode it broadcasts an intent containing the barcode. I then grab the barcode and process it as appropriate.


This all works well, but for reason when it decodes a barcode beginning with the letter 'B' it launches the browser, and if the barcode begins with a letter 'E' it opens the Complete Action Using dialog giving the user the option to choose from Email and Gmail (this is because I had not selected a default emailing app).


What I would like to know is, why is this behavior happening and how can I prevent it from happening that the event remains within my application?


Here is my broadcast receiver:



IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ScannerAction);
scannerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
receivedBarcode(intent);
}
};
this.cordova.getActivity().registerReceiver(scannerReceiver, intentFilter);


Here is where I add a listener for the search button press:



private void bindKeyEvents(){
final Context context = this.cordova.getActivity();
this.webView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
if (event.getAction() == KeyEvent.ACTION_UP){
if (isPressed){
//Engage Scanner
Log.w("testApp", "Release");
isPressed = false;
}
return true;
}
if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()){
Log.w("testApp", "Long Press");
return true;
}
if (event.getAction() == KeyEvent.ACTION_DOWN){
event.startTracking();
if (!isPressed){
//Disengage Scanner
Log.w("testApp", "Press");
isPressed = true;
}
return true;
}
return true;
}
else{
return false;
}
}
});
}

0 comments:

Post a Comment