【问题标题】:intent to google maps from webview意图从 webview 谷歌地图
【发布时间】:2015-10-03 04:06:20
【问题描述】:

我在 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>

【问题讨论】:

    标签: android android-intent webview


    【解决方案1】:

    试试这个代码......!

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多