读书人

缴获浏览器的连接

发布时间: 2012-09-28 00:03:35 作者: rapoo

截获浏览器的连接

1.截获自己的浏览器中的连接

private class MyWebViewClient extends WebViewClient {?
? ? @Override?
? ? public boolean shouldOverrideUrlLoading(WebView view, String url) {?
? ? ? ? setUrlparams(url);?
?
? ? ? ? if (url.indexOf("pattern") != -1) {?
? ? ? ? ? ? // do something?
? ? ? ? ? ? return false;?
? ? ? ? } else {?
? ? ? ? ? ? view.loadUrl(url);?
? ? ? ? }?
?
? ? ? ? return true;?
? ? }?
?
}?

2. 截获自带浏览器的连接

<activity?? ? ? ? android:name=".PhotostreamActivity"?
? ? ? ? android:label="@string/application_name">?
?
? ? ? ? <!-- ... --> ? ? ? ? ? ??
?
? ? ? ? <intent-filter>?
? ? ? ? ? ? <action android:name="android.intent.action.VIEW" />?
? ? ? ? ? ? <category android:name="android.intent.category.DEFAULT" />?
? ? ? ? ? ? <category android:name="android.intent.category.BROWSABLE" />?
? ? ? ? ? ? <data android:scheme="http"?
? ? ? ? ? ? ? ? ? android:host="flickr.com"?
? ? ? ? ? ? ? ? ? android:pathPrefix="/photos/" />?
? ? ? ? ? ? <data android:scheme="http"?
? ? ? ? ? ? ? ? ? android:host="www.flickr.com"?
? ? ? ? ? ? ? ? ? android:pathPrefix="/photos/" />?
? ? ? ? </intent-filter>?
? ? </activity>?

final Intent intent = getIntent();?
? ? final String action = intent.getAction();?
?
? ? if (Intent.ACTION_VIEW.equals(action)) {?
? ? ? ? final List<String> segments = intent.getData().getPathSegments();?
? ? ? ? if (segments.size() > 1) {?
? ? ? ? ? ? mUsername = segments.get(1);?
? ? ? ? }?
? ? }?

该方法要注意检查vapi是否已经发生变化

读书人网 >移动开发

热点推荐