在一些手机上,url的地址栏上面输入wtai://wp/mc;10086就会自动跳转到拨打10086的界面。
输入
wtai://wp/mc;10010就会进入到拨打10010的界面。
这种功能是怎么实现的呢?自己也进行了一定的研究。
diff --git a/src/com/android/browser/NavigationBarBase.java b/src/com/android/browser/NavigationBarBase.java
index daeb1de..6bec737 100644
--- a/src/com/android/browser/NavigationBarBase.java
+++ b/src/com/android/browser/NavigationBarBase.java
@@ -172,12 +172,13 @@ public class NavigationBarBase extends LinearLayout implements
boolean wap2estore = SystemProperties.getBoolean(
"persist.env.browser.wap2estore", false);
if ((wap2estore && isEstoreTypeUrl(text))
+ || isWtaiTypeUrl(text)) {
url = text;
} else {
url = UrlUtils.smartUrlFilter(text, false);
}
-
Tab t = mBaseUi.getActiveTab();
// Only shortcut javascript URIs for now, as there is special
// logic in UrlHandler for other schemas
@@ -199,7 +200,19 @@ public class NavigationBarBase extends LinearLayout implements
return;
}
}
+ Log.e(TAG,"bar url = " + url);
+ if (url != null && t != null && isWtaiTypeUrl(url))
+ {
+ if(handleWtaiTypeUrl(url))
+ {
+ return;
+ }
+ }
}
+
Intent i = new Intent();
String action = Intent.ACTION_SEARCH;
i.setAction(action);
@@ -256,6 +269,21 @@ public class NavigationBarBase extends LinearLayout implements
}
}
+ private boolean isWtaiTypeUrl(String url) {
+ String utf8Url = null;
+ try {
+ utf8Url = new String(url.getBytes("UTF-8"), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ Log.e(TAG, "err " + e);
+ }
+ if (utf8Url != null && utf8Url.startsWith("wtai://wp/mc;")) {
+ return true;
+ }
+ return false;
+ }
+
String utf8Url = null;
try {
@@ -269,6 +297,21 @@ public class NavigationBarBase extends LinearLayout implements
return false;
}
+ private boolean handleWtaiTypeUrl(String url) {
+ Intent intent;
+ // perform generic parsing of the URI to turn it into an Intent.
+ intent = new Intent(Intent.ACTION_VIEW, Uri.parse(WebView.SCHEME_TEL + url.substring(("wtai://wp/mc;").length())));
+ try {
+ mContext.startActivity(intent);
+ } catch (ActivityNotFoundException ex) {
+ Log.w("Browser", "No resolveActivity " + url);
+ return false;
+ }
+ return true;
+ }
+
private boolean handleRtspTypeUrl(String url) {
Intent intent;
// perform generic parsing of the URI to turn it into an Intent.
具体原理是在传入url的时候,判断类型,然后new一个intent去实现这个功能。