2017-02-20 79 views
0

我正在使用構建變體,並希望捕獲基於變體的其他鏈接。我希望所有的變體捕獲來自主機的一個環節,所以我已經宣佈了intent-filter在我的主AndroidManifest.xml文件像這樣:Android應用鏈接多個意圖過濾器主機和清單合併不工作

<activity android:name=".activity.DeepLinkActivity" 
android:noHistory="true"> 
    <intent-filter android:autoVerify="true"> 
    <action android:name="android.intent.action.VIEW"/> 
    <category android:name="android.intent.category.BROWSABLE"/> 
    <category android:name="android.intent.category.DEFAULT"/> 

    <data android:host="hostOne.com" android:path="/page.aspx" android:scheme="http"/> 

    </intent-filter> 
</activity> 

我也產生了其他變體的部分清單,如hostTwo.com像這樣:

<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain"> 
    <application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile"> 
    <activity android:name=".activity.DeepLinkActivity"> 
     <intent-filter android:autoVerify="true"> 
     <action android:name="android.intent.action.VIEW"/> 
     <category android:name="android.intent.category.BROWSABLE"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
     <data android:scheme="http://" android:host="hostTwo.com" android:path="/page.aspx"/> 
     </intent-filter> 
    </activity> 
    </application> 
</manifest> 

它是根據在構建變種(based upon the documentation here)和Android工作室的合併清單視圖放置在適當命名的文件夾顯示,intent-filter用於主機2已被加入到最終的合併清單,但是,模擬器或實際設備發生故障捕捉意圖的意圖e第二主機。

我生成的意圖,像這樣在命令提示符:

adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hostone.com/page.aspx" 

該協會致力於hostone,但這樣做

,因爲應用程序無法捕捉到它會啓動瀏覽器。

做的Android應用程序鏈接只適用於一個主機名?還有什麼我可以嘗試的嗎?

+0

檢查所生成的AndroidManifest文件(在Android Studio中打開apk文件) –

+0

'主機= 「hostOne.com」'' 主機= 「hostTwo」' 莫非此差小成爲問題?(您錯過.com)在我的情況下,我使用了一個針對不同主機的兩個意向過濾器。 – Michael

+0

@Michael在我編輯出所用的實際網站時出現了錯誤:)如果將所有數據標記放在一個意圖過濾器聲明中,我可以在部分聲明中做到這一點,但我會而不是我不必爲每個風味/變體組合生成一個組合 –

回答

0

我發現部分清單是不正確的。在intent-filterdata標記中,android:scheme="http://"由於尾隨://而無效。

根據google's documentation,Android構建了intent-filter這樣的URI:<scheme>://<host>:<port>/<path>因此將它包含在聲明中是不必要的。

將聲明更改爲android:scheme="http"後,合併繼續成功,操作系統嘗試驗證部分清單中定義的鏈接!

校正的部分清單:

<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain"> 
    <application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile"> 
    <activity android:name=".activity.DeepLinkActivity"> 
     <intent-filter android:autoVerify="true"> 
     <action android:name="android.intent.action.VIEW"/> 
     <category android:name="android.intent.category.BROWSABLE"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
     <data android:scheme="http" android:host="hostTwo.com" android:path="/page.aspx"/> 
     </intent-filter> 
    </activity> 
    </application> 
</manifest>