码迷,mamicode.com
首页 > 移动开发 > 详细

Android通过网页启动APP

时间:2015-01-28 18:03:05      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

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,就可以启动了。

Android通过网页启动APP

标签:

原文地址:http://blog.csdn.net/heqiangflytosky/article/details/43232369

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!