Webページには、Androidアプリを開きます

分析の原則

:Androidプラットフォームの面では、URIは、3つの部分に分かれ
スキーム、権限、パス
権限がホストとポートに分割されています。形式は次のとおりです。

<scheme>://<host>:<port>[<path>|<pathPrefix>|<pathPattern>]

マニフェストに対応<data>次のように構成されました。

<data android:host=""
      android:mimeType=""
      android:path=""
      android:pathPattern=""
      android:pathPrefix=""
      android:port=""
      android:scheme=""
      android:ssp=""
      android:sspPattern=""
      android:sspPrefix=""/>

スキームは無効!あり、他の属性を指定しない場合は、パラメータする場所を
ホストが指定されていない場合は、ポート、パス、Pathprefixは、pathPatternは無効です!

私たちの最も一般的に使用されるschemehostportpath4つの構成。

実装

まず、AndroidManifestMainActivity1の追加<intent-filter>

<intent-filter>  
      <action android:name="android.intent.action.VIEW" />  
      <category android:name="android.intent.category.BROWSABLE" />  
      <category android:name="android.intent.category.DEFAULT"/>  
      <data android:scheme="protocol" android:host="domain" android:pathPrefix="/link" />  
  </intent-filter>  

次に、あなたのウェブページにリンクを追加します。

<a href="protocol://domain/link>打开app</a>

アプリはおめでとうございます、その後、正常にイジェクトされた場合は最後に、リンクをクリックして、あなたは成功しました。

広げます

オープンアプリはそれにデータを渡す方法、時には我々はデータを転送する必要があり、十分な光ではないかもしれませんか?

私たちは、アプリに、いくつかのデータを上記の方法を使用することができ、それを変更するにはリンクされています

<a href="protocol://domain/link?id=123>打开app并传递id</a>

そして、アプリでMainActivityのonCreateメソッドにコードを追加します。

Uri uri = getIntent().getData();  
String id= uri.getQueryParameter("id");  

これは、データを転送することができます!

アプリケーション内のWebView、データ取得操作の場合:

webView.setWebViewClient(new WebViewClient(){
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Uri uri=Uri.parse(url);
      if(uri.getScheme().equals("protocol")&&uri.getHost().equals("domain")){
        String id = uri.getQueryParameter("id");
          }else{
              view.loadUrl(url);
          }
        return true;
  }
});

API

getScheme(); //获得Scheme名称 

getDataString(); //获得Uri全部路径 

getHost(); //获得host

公式のAPIのURIリンク接続し
ます。https://developer.android.comを...

コメントは歓迎します

おすすめ

転載: www.cnblogs.com/homehtml/p/12505749.html