AndroidのDeepLink

18232 ワード

知っているうちに他の人からリンクが来て、クリックするとアプリケーションで開くようにヒントが表示されます.具体的な実現方法は何ですか?そしてgoogleはdeeplinkです.簡単にユーザー体験から言えば、Deep Linkは、携帯電話のブラウザ/Google Searchで検索結果をクリックすると、インストールされているアプリケーションのいずれかのページに直接ジャンプできる技術です.実は日常的に使う中でユーザーのも比較的に広いです.deeplinkはappA起動aapBとは異なります.彼はウェブリンクの形で実現した.私たちは彼の具体的な実現方法を見てみましょう.ブラウザのURLリンクをクリックして、特定のアプリを起動します.
まずHTMLのページを作成します.ページの内容のフォーマットは以下の通りです.
<a href="[scheme]://[host]/[path]?[query]">      a> 

この一言でいいです.
各項目の意味は以下の通りです.
scheme:起動したAppを判別します.※詳しくは後述する
ホスト:適宜記述
path:送信時に必要なキー※なくても良い
Query:値を取得するKeyとValue※なくても良い
テストとしてよく書きましたが、私たち一人一人の携帯電話には微信があるでしょう.次のようになります.
<a href="http://weixin.qq.com/r/?name=zhangsan&age=26">    a> 

微信のプロファイルを逆コンパイルした結果、
        <activity android:theme="2131492878"
             android:name="com.tencent.mm.plugin.setting.ui.qrcode.GetQRCodeInfoUI"
             android:permission="com.tencent.mm.permission.GET_QRCODE_INFO"
             android:exported="0"
             android:configChanges="1184">
            <intent-filter>
                <action android:name="android.intent.action.VIEW">
                action>
                <category android:name="android.intent.category.DEFAULT">
                category>
                <category android:name="android.intent.category.BROWSABLE">
                category>
                <data android:scheme="http"
                     android:host="weixin.qq.com"
                     android:pathPrefix="/r/">
                data>
            intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW">
                action>
                <category android:name="android.intent.category.DEFAULT">
                category>
                <category android:name="android.intent.category.BROWSABLE">
                category>
                <data android:scheme="weixin" android:host="qr">
                data>
            intent-filter>
        activity>

私たちはこの部分に重点を置いています.
  <data android:scheme="http"
                     android:host="weixin.qq.com"
                     android:pathPrefix="/r/">
                data>

つまり、私たちが必要なものをクリックしてホームページのリンクをクリックすればいいのです.まだやっていません.明日サーバーに掛けてみます.
自分でappを書いて試してみることもできますが、リンクも以下の通りです.
<a href="http://weixin.qq.com/r/">    a> 

次にandroidプログラムを新規作成してmanifestファイルを構成します.
    <activity
            android:name="com.example.jiemidaima.Readphonecontact"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="http"
                     android:host="weixin.qq.com"
                     android:pathPrefix="/r/">
                data>
            intent-filter>
        activity>

次にactivityファイルに転送された値を取得します.
Intent i_getvalue = getIntent();  
String action = i_getvalue.getAction();  

if(Intent.ACTION_VIEW.equals(action)){  
    Uri uri = i_getvalue.getData();  
    if(uri != null){  
        String name = uri.getQueryParameter("name");  
        String age= uri.getQueryParameter("age");  
    }  
}

基本コードが書き終わりました.明日サーバーに掛けてみたら、サーバーでこのリンクを掛けてみましたが、開けられないようです.
<a href="https://weixin.qq.com/cgi-bin/readtemplate?t=weixin">    a> 

この一言は微信がダウンロードしたurlを開くしかない.微信を開くことはできません.すでに実現されています.
<a href="weixin://qr">open wechata>

アップルもアンドロイドも実現できます.しかし、プロセスが保証されている場合でなければなりません.そして私もqqブラウザを試しただけです.———7/29補足http://jaq.alibaba.com/community/art/show?spm=a313e.7916648.0.0.Axxq92&articleid=265アリセキュリティ上のウェブページオープンappに関する記事では、ユーザーがカスタマイズしたURI scheme(Custom URI scheme)つまりdeeplink、もう1つは「intent:」文法(Intent-based URI)の2つの方法について述べています.1つ目はdeeplinkです
私は自分でapkを書いて、それからwebページの実装コードを盗むために起動しました:サーバーコード端:
<a href="uzi://qq?http://***">      a>

appコードは以下の通りです:プロファイル、対応するschemeとhostに注意してください
<uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.cannotstopservers.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

           intent-filter>
           <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="uzi" android:host="qq"/>
           intent-filter> 
        activity>
           <activity
            android:name="com.example.cannotstopservers.webviewMainActivity"
            android:label="@string/app_name" >
        activity>

そしてMainactivity
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    Intent intent=getIntent();
    Uri uri=intent.getData();
    if(uri!=null){
        String url=uri.getQueryParameter("load_url");
        Intent webviewIntent=new Intent();
        webviewIntent.putExtra("load_url", url);
        ComponentName componet=new ComponentName("com.example.cannotstopservers","com.example.cannotstopservers.webviewMainActivity");
        webviewIntent.setComponent(componet);
        startActivity(webviewIntent);

    }
    }

}

WebviewActivityでWebページを開くには、次のようにレイアウトします.
<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"
    tools:context="com.example.cannotstopservers.MainActivity$PlaceholderFragment" >

<WebView 
    android:id="@+id/web1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

LinearLayout>

Activityのコードは次のとおりです.
public class webviewMainActivity extends Activity {
    private WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        //new   webview         url  load
         webview=(WebView) findViewById(R.id.web1);
        Intent intent = getIntent();
        String    url = intent.getStringExtra("load_url");
        if(url!=null){
        webview.loadUrl(url);
        }

    }

}

urlをクリックしてappを起動し、釣りインタフェースを表示する機能を実現しました.