我在Android中有一个webView,我在其中打开一个html网页。谷歌地图有几个链接,我想打算本机应用程序。我已设置任何其他链接到我的主机文件将意图本机应用程序。我尝试了其他几种但也失败了。有什么想法吗?
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// When user clicks a hyperlink, load in the existing WebView
if(Uri.parse(url).getHost().endsWith("googledrive.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
的AndroidManifest.xml
<intent-filter>
<data
android:host="maps.apple.com"
android:pathPattern="/.*"
android:scheme="http" >
</data>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.VIEW" />
</intent-filter>
答案 0 :(得分:0)
试试此代码......!
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
/*
*
* THis class create for browser handaling.
*
*/
public class SimpleBrowser extends Activity implements OnClickListener {
EditText url;
WebView ourBrow;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.simplebrowser);
ourBrow = (WebView) findViewById(R.id.wvBrowser);
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
ourBrow.setWebViewClient(new OurViewClient());
try {
ourBrow.loadUrl("http://admstest.netau.net/ADMS/View/LoginView.php");
} catch (Exception e) {
e.printStackTrace();
}
}
}
XML布局..........!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="10" >
<EditText
android:id="@+id/etURL"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:inputType="text"
tools:ignore="TextFields" />
<Button
android:id="@+id/bGo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text="Go"
tools:ignore="HardcodedText" />
</LinearLayout>
<WebView android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/wvBrowser"/>
</LinearLayout>
AndroiMainfest.xml
<activity
android:name="viewActivity.SimpleBrowser"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SIMPLEBROWSER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>