2015-02-09 65 views
2

我試圖獲取點擊的URL來打開應用程序。我只是無法找到我可以得到的信息。點擊時我有一個打開應用程序的清單。鏈接將是「http://host.com/file.html?param=1&param2=2」,我試圖給應用程序來處理。用Intent獲取url Android

<intent-filter> 
      <data android:scheme="http" 
       android:host="host.com" 
       android:pathPrefix="/file.html" /> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 

編輯

@Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     Intent intent = getIntent(); 
     Uri uri = intent.getData(); 
     try { 
      url = new URL(uri.getScheme(), uri.getHost(), uri.getPath()); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
} 

回答

2

你應該能夠得到的意圖的數據在你的活動有以下幾點:

Uri uri = this.getIntent().getData(); 
URL url = new URL(uri.getScheme(), uri.getHost(), uri.getPath()); 
+0

我說我現在的onCreate方法往上頂。儘管如此,似乎還沒有工作。 – 2015-02-10 00:34:40

+0

什麼不起作用?你能提供一個堆棧跟蹤嗎? – 2015-02-10 15:11:43

+0

我的onCreate方法似乎沒有被調用,根據我的理解,當系統調用onCreate時它將被調用,並且它將重定向到我通過重寫它而創建的onCreate。 – 2015-02-10 18:44:59