wildabeast / BarcodeScanner

Official repository now at [phonegap/phonegap-plugin-barcodescanner](http://github.com/phonegap/phonegap-plugin-barcodescanner).
967 stars 741 forks source link

Back Button Issue on Android #97

Open joydragon opened 10 years ago

joydragon commented 10 years ago

I'm using the plugin on my app and I have the following issue: I have a main page and a button to call the scanner, whenever I press the back button on the emulator and supposedly go back to the main page the back button event is kept fired so I handle it on the main page and the app exits (because of me handling that event there). I'm testing it on the android emulator setting the Virtual Device with the settings as a Nexus 4 with KitKat (4.4.2), and with a Nexus 4 phone as well. The weird thing is that if I tried the same app on a Samsung Galaxy S3 the app doesn't receive that event and it doesn't exit (until you press the back button again).

Thanks

rafalzmuda commented 10 years ago

I have the same issue. When I press back button while scanner is active then backbutton event is somehow fired after scanner dissapears causing my app to go back one screen (or close if it was app's main screen). It only happens on android 4.4.2. On android <= 4.3 all works fine. There's also problem with success callback - it seems like it's not fired at all.

spint002 commented 10 years ago

I was having the exact same issue (Android 4.4.2). I found this link, which has a hack that solves the issue.

http://marsbomber.com/2014/05/29/BarcodeScanner-With-Ionic/

huangliop commented 10 years ago

i fix this issue. com.google.zxing.client.android.CaptureActivity.java delete this case KeyEvent.KEYCODE_BACK: if (source == IntentSource.NATIVE_APP_INTENT) { setResult(RESULT_CANCELED); finish(); return true; } if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) { restartPreviewAfterDelay(0L); return true; } break; and add this @Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (source == IntentSource.NATIVE_APP_INTENT) { setResult(RESULT_CANCELED); finish(); return true; } if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK) && lastResult != null) { restartPreviewAfterDelay(0L); return true; } break; } return super.onKeyUp(keyCode, event); }

elmato commented 9 years ago

Same issue with Android 4.4.4

peterzebird commented 9 years ago

Same on 5.1

fantasybei commented 9 years ago

+1 on 4.4.2

pierresh commented 9 years ago

Hello, I have the same issue with Android 5.0.2. Interesting to note that this problem does not occur with the Camera plugin.

Thanks!

javierverb commented 8 years ago

+1

jefferscn commented 7 years ago

+1

daniefvh commented 7 years ago

+1

I wonder if a crappy workaround is to put it on a modal, then auto fire the barcode scanner when the modal opens and auto dismisses when the modal barcode scanner completes. Then just pipe the value all the way back then the caller... Will try it out and see if it works.