使用Webview进入一个页面,这个页面需要调用手机里的一个软件。怎么让他调用
http://blog.csdn.net/xyz_lmn/article/details/39473701
方法有很多种,我这里说一种,
通过隐式意图调用。
那么如何自定义隐式意图。AndroidMainfest.xml中
android:name=".activitys.MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<category android:name="android.intent.category.DEFAULT" />
<!-- 接受的数据描述 表示数据格式开头 -->
<!-- mimeType表示数据类型 若没有标准格式 一般写为vnd.android.cursor.item/xxx -->
<data
android:mimeType="vnd.android.cursor.item/pas"
android:scheme="pas" />
</intent-filter>
</activity>
然后webView.setWebViewClient的shouldOverrideUrlLoading()方法里
// 处理自定义scheme
if (!url.contains("http")) {
Log.e(TAG, "url:" + url);
try {
// 以下固定写法
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
mContext.startActivity(intent);
} catch (Exception e) {
// 防止没有安装的情况
e.printStackTrace();
}
return true;
}
比如QQ登录调用的Url是这样的
mqqwpa://im/chat?sigt=2DCA98C10B094D2D9854B11085F6C1C49C0048B2F876EE7F42FFE57F070C113EE9B86DC04107DD0F16F2429AFEAE4BF7CC9E00DB42F4A8DEEF6A5F0DC2360BF18390672ACD8AFEECA2695F87FAC33B73715B238593BC97F7D337B90171A25EC562B92184893CC1F818E0A138E1E27CC10A4B4472B53BD593F7FFC4A8383C6A11&chat_type=crm&uin=2852388039&version=1&src_type=web&web_src=1&wpaType=1&assignId=54&QidianSigT=2DCA98C10B094D2D9854B11085F6C1C49C0048B2F876EE7F42FFE57F070C113EE9B86DC04107DD0F16F2429AFEAE4BF7CC9E00DB42F4A8DEEF6A5F0DC2360BF18390672ACD8AFEECA2695F87FAC33B73715B238593BC97F7D337B90171A25EC562B92184893CC1F818E0A138E1E27CC10A4B4472B53BD593F7FFC4A8383C6A11&QidianKfUin=2852135811&rkey=5148fcdc02db5a87415637f64d3d1681&env=
打开不同的程序,Url也不一样,需要百度上搜索其隐式意图的写法