adding code from cordova/PhoneGap