2011-03-28 100 views
0

我試過以下關於Intents和Intent Filters的文章,希望將我的應用從顯式轉移到隱式意圖(似乎讓事情變得更簡單)。然而,我的Intents從來沒有匹配,無論我多努力嘗試。相關信息如下:爲什麼我的意圖不匹配?

Intent in = new Intent(Intent.ACTION_VIEW, Provider.constantsUri); 
    //in.addCategory(Intent.CATEGORY_DEFAULT); is this required? 
    startActivity(in); 

,並在我的清單:

<activity android:name="Equation" > 
      <intent-filter> 
       <action android:name="android.intent.action.VIEW"></action> 
       <data android:scheme="content" android:host="com.espian.formulae.pro" android:path="const"></data> 
       <category android:name="android.intent.category.DEFAULT"></category> 
      </intent-filter> 
     </activity> 

和constantsUri的定義:

public static Uri constantsUri = Uri.parse("content://com.espian.formulae.pro/const"); 

我也試過用Uri.Builder形成Uri,但沒有要麼運氣。有什麼明顯的我失蹤了嗎?

回答

0

我在我的應用程序之一是這樣定義的意圖:

<activity android:name=".TwitterAuthActivity"> 
     <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="moodfling" android:host="twitterauth" /> 
     </intent-filter> 
    </activity> 

如果我把這個新的測試程序:

Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("moodfling://twitterauth")); 
    startActivity(in); 

它啓動的活動。聽起來你的過濾器定義中有些東西是錯誤的,但我不知道什麼是非正式的。嘗試複製我的版本並確保它適用於您,然後嘗試在更換零件時縮小版本。

+0

看來,如果我只有一個計劃和主機在數據(如你的例子)它的工作原理,但如果我把一個路徑(這是必需的),它不匹配?事情是,這個例外說沒有什麼與Uri解析的_exact相同的Uri_匹配。將嘗試使用數據類型 – 2011-03-29 21:16:43

+0

您確定您的路徑正確嗎?我想如果你從你的例子中記錄constantsUri.getPath(),它實際上會顯示「/ const」。嘗試更改您的意圖過濾器以包含前導斜槓。 – mikerowehl 2011-03-29 21:34:10

+0

您評論中概述的內容有效(即它需要前導斜線)謝謝:) – 2011-05-23 01:19:26

相關問題