我的支付宝链接是这个: https://qr.alipay.com/apinwknfu52rsy9797
写在前面:上面那个链接是通过扫描自己的支付宝二维码得出来的,然后在代码中加入一个webview控件,先进行一通设置最后loadurl(链接)。因为很简单,所以写出来(划掉)。
static final String UA = "Mozilla/5.0 (Linux; Android " + Build.VERSION.RELEASE + "; "
+ Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry().toLowerCase()
+ "; Nexus 5 Build/JOP40D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Mobile Safari/537.36";
WebView mWeb = (WebView) findViewById(R.id.webView2);
mWeb.getSettings().setAllowFileAccess(true);
mWeb.getSettings().setJavaScriptEnabled(true);
mWeb.getSettings().setUseWideViewPort(true);
mWeb.getSettings().setLoadWithOverviewMode(true);
/*
* fixed issues #12
* http://stackoverflow.com/questions/9476151/webview-flashing-with-white-background-if-hardware-acceleration-is-enabled-an
*/
if(Build.VERSION.SDK_INT >= 11)
mWeb.setBackgroundColor(Color.argb(1, 0, 0, 0));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
}
mWeb.setWebChromeClient(new WebChromeClient());
mWeb.getSettings().setUserAgentString(UA);
mWeb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(uri);
if ("alipayqr".equals(uri.getScheme()) || "alipays".endsWith(uri.getScheme())) {
try {
startActivity(intent);
finish();
} catch (Exception e) {
e.printStackTrace();
showErrorDialog();
}
return true;
} else if (url.startsWith("http") && url.endsWith(".apk")) {
startActivity(intent);
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
mWeb.loadUrl("https://qr.alipay.com/apinwknfu52rsy9797");
部分代码不是必须的,但是我不管
demo没有