0

我試圖爲我的應用程序實現應用程序索引,但我不太確定我應該返回爲應用程序索引ActionappUri如何使用庫項目實現應用程序索引?

比方說,我有一個包名com.example.myappwebUrihttp://example.com/some/path

據我所知,在這種情況下appUri通常會是com.example.myapp/http/example.com/some/path,對嗎?

現在輸入我的應用程序使用的庫項目以及索引活動的存在位置。我們稱之爲圖書館項目com.example.mylibrary和索引活動MyActivity

如果我想使用亞行啓動活動,我會用

adb shell am start -W -a android.intent.action.VIEW -d "http://example.com/some/path" com.example.myapp/com.example.mylibrary.MyActivity

所以,我的問題是 - 什麼應該appUri爲應用程序索引Action在這種情況下?活動是否屬於圖書館項目,是否會受到影響?

回答

0

一般來說,您可以通過庫提供的Action.Builder來構建Action。作爲你需要提供相關的URI。所以,如果你想索引視圖行動,你應該提供產品的URI,這是查看。

Uri.Builder builder = new Uri.Builder(); 
    String uriStr = builder 
     .scheme("http") 
     .authority("example.com") 
     .appendPath("some/path").build().toString(); 

    Action action = new Action.Builder(Action.Builder.VIEW_ACTION) 
     .setObject("productName", uriStr) 
     .build(); 


有關詳細信息,你可以看看logging actions docs和他們的示例應用程序。
測試:

adb shell am start -a android.intent.action.VIEW -d "{URL}" {package name} 

其中{包名} = com.example.myapp和URL = http://example.com/some/path

最後,你的活動放在庫裏應該有意圖過濾器,它可以處理你的URI http://example.com/some/path

+0

不好意思,但是你的'adb'命令不適合我,我得到'Error:Activity not started,unable to resolve Intent'。我相信這是因爲這個活動是在圖書館項目中,這就是我首先提出這個問題的原因(請參閱問題中的'adb'命令 - 因爲它引用了圖書館項目,所以這是行得通的)... – BadCash

+0

我的不好 - 原來URL周圍的引號不知怎麼地被弄亂了,變成了那些奇怪的引號('「」')!出於某種原因導致錯誤:活動未啓動,僅在使用軟件包名稱時無法解析Intent,但在指定完整軟件包名稱+活動時工作正常。問題解決了。 – BadCash

相關問題