ported from phonegap
ported from phonegap