Android解析Intent协议并打开程序

我现在写的程序是基于webview的,程序中又遇到了网页版支付宝支付,里面就有这么一个链接,这个链接在访问之后,会打开支付宝程序:
intent://platformapi/startapp?appId=20000013&pwdType=ordinaryPassword&_t=1456301771669#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end
看下这个东西是怎么生成的:http://bbs.mobiletrain.org/thread-31234-1-1.html 具体关于这个的介绍(我怕链接没了,所以转载了 2017年12月01日19:15:35更新:乌云果然没了,哎..):Intent scheme URL attack或者原文:http://drops.wooyun.org/papers/2893 人家是黑程序的,不过最后也好心给了上面的链接解析的方法:
// convert intent scheme URL to intent object  
Intent intent = Intent.parseUri(uri);  
// forbid launching activities without BROWSABLE category  
intent.addCategory("android.intent.category.BROWSABLE");  
// forbid explicit call  
intent.setComponent(null);  
// forbid intent with selector intent  
intent.setSelector(null);  
// start the activity by the intent  
context.startActivityIfNeeded(intent, -1);  
上面是前几年的代码,现在已有所改动,Intent.parseUri参数已经变了,参看下面的代码:
Intent intent;
try {
	intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
	// forbid launching activities without BROWSABLE
	// category
	intent.addCategory("android.intent.category.BROWSABLE");
	// forbid explicit call
	intent.setComponent(null);
	// forbid intent with selector intent
	intent.setSelector(null);
	// start the activity by the intent
	startActivityIfNeeded(intent, -1);
} catch (URISyntaxException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
亲测成功
mNewWebView.setWebViewClient(new WebViewClient() {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			// intent://platformapi/startapp?appId=20000013&pwdType=ordinaryPassword&_t=1456301771669#Intent;scheme=alipays;package=com.eg.android.AlipayGphone;end
			if (url.startsWith("intent://")) {
				Intent intent;
				try {
					intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
					// forbid launching activities without BROWSABLE
					// category
					intent.addCategory("android.intent.category.BROWSABLE");
					// forbid explicit call
					intent.setComponent(null);
					// forbid intent with selector intent
					intent.setSelector(null);
					// start the activity by the intent
					startActivityIfNeeded(intent, -1);
				} catch (URISyntaxException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return true;				
                         }
			view.loadUrl(url);
			return true;
		}
	});
如果想要尝试的话可以用上面的webview访问:https://mobile.alipay.com/index.htm?cid=wap_dc
(转)Intent scheme URL attack 2016-02-24
我懂Java,然而我懵逼了= = 2016-03-04

评论区