我没有使用过 Phonegap,但如果我需要从 HTML 页面启动 Play 商店,我会这样做:
爪哇
public class MyClass extends AbstractClass {
// lots of lines of code
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "PlayStore");
// moar code
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void launch() {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.publishername.myapp"));
mContext.startActivity(intent);
}
}
// and many moar
}
HTML/Javascript
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function launchPlayStore() {
PlayStore.launch();
}
</script>
</head>
<body>
<!-- lots of lines of html -->
<a href="javascript:launchPlayStore();">Link to market</a>
<!-- moar html -->
</body>
</html>