(Android) catches the buckbutton event
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170711-2345" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta2-20170713-1540" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -287,11 +287,25 @@ var saltHash = Math.floor(Math.random() * Date.now());
cacheZIndex = {};
setTimeout(putHtmlElements, 0);
}
- //document.addEventListener("backbutton", resetTimer); // <-- Cordova allows to register only one event listener
+
document.addEventListener("deviceready", resetTimer);
document.addEventListener("plugin_touch", resetTimer);
window.addEventListener("orientationchange", resetTimer);
+ // Catches the backbutton event
+ // https://github.com/apache/cordova-android/blob/55d7cf38654157187c4a4c2b8784191acc97c8ee/bin/templates/project/assets/www/cordova.js#L1796-L1802
+ var APP_PLUGIN_NAME = Number(require('cordova').platformVersion.split('.')[0]) >= 4 ? 'CoreAndroid' : 'App';
+ document.addEventListener("backbutton", function() {
+ // Executes the browser back history action
+ exec(null, null, APP_PLUGIN_NAME, "backHistory", []);
+ resetTimer();
+
+ // For other plugins, fire the `plugin_buckbutton` event instead of the `backbutton` evnet.
+ var event = document.createEvent('plugin_buckbutton');
+ event.initEvent(eventName, false, false);
+ document.dispatchEvent(event);
+ }, false);
+
}());
/*****************************************************************************

(Android) catches the buckbutton event