2015-09-23 114 views
0

我很難弄清楚這裏有什麼問題。我得到了它與這個意圖過濾器的活動:Uri.parse和Uri.Builder給出相同的uri但不同的結果

<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="launcher" 
     android:host="custo" 
     /> 
    </intent-filter> 

我成功地做(路徑和參數在代碼進一步處理)推出我的活動:

context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("launcher://custo/3dw?iuid=06eec76c-f48e-4961-870e-4b27495f8201")); 

但是這一次不工作:

Uri uri = new Uri.Builder().scheme("launcher").appendEncodedPath("/custo").appendPath("3dw").appendQueryParameter("iuid", "f6f18a3d-14f9-4969-8a24-8130f4cad5d1").build(); 
context.startActivity(new Intent(Intent.ACTION_VIEW, uri); 

錯誤是:

無法用意圖「act = ... action.VIEW dat =」啓動器:// custo/3dw?iuid = 06eec76c-f48e-4961-870e-4b27495f8201「(與我解析的字符串相同)啓動活動。

怎麼了?

回答

1

在第二個示例中,您的Uri缺少框架必須查找的authority。它看起來像在第一個有效Uri,但不是給人一種權威,你是給這使得您Uri看起來像一個路徑下(注意失蹤/方案後):

啓動:/丘斯托/ 3DW IUID = f6f18a3d-14f9-4969-8a24-8130f4cad5d1

你的說法應該是:

new Uri.Builder() 
    .scheme("launcher") 
    .authority("custo") 
    .appendPath("3dw") 
    .appendQueryParameter("iuid", "f6f18a3d-14f9-4969-8a24-8130f4cad5d1") 
    .build(); 
+0

就是這樣,非常感謝。 – ValPar

相關問題