Android通过网页启动APP
http://www.cnblogs.com/yejiurui/p/3413796.html
1、测试网页
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>TestStartApp</title> </head> <body> <a href="m://test.com/?package=com.tencent.mobileqq&arg1=1">打开QQ</a><br/> </body> </html>
2、需要对WebView设置如下:
private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); // if (savedInstanceState == null) { // getSupportFragmentManager().beginTransaction() // .add(R.id.container, new PlaceholderFragment()).commit(); // } mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.e("Test", url); Uri uri=Uri.parse(url); if(uri.getScheme().equals("m")&&uri.getHost().equals("test.com")){ String pkgName=uri.getQueryParameter("package"); String arg1=uri.getQueryParameter("arg1"); Log.e("Test", "package = "+pkgName+", arg1 = "+arg1); Intent intent =null; intent = getPackageManager().getLaunchIntentForPackage(pkgName); if(intent != null){ startActivity(intent); } return true; }else return super.shouldOverrideUrlLoading(view, url); } }); mWebView.loadUrl("http://***************/testApp.html"); }
点击打开QQ,如果你手机上安装了QQ,就可以启动了。
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。