2011-08-02 70 views
6

我正在開發一個下載圖像的應用程序。當用戶點擊下載圖片鏈接時,我已成功觸發我的應用。如何過濾特定網址?「意圖過濾器」中的android過濾器網址

這裏我的清單代碼:

<activity android:theme="@style/Transparent" android:name=".DownloadImage" 
     android:label="@string/app_name"> 
     <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:mimeType="image/*" android:host="*" 
       android:scheme="http" /> 
     </intent-filter> 
</activity> 

我的應用程序將啓動,並下載圖像時,用戶點擊任何鏈接在瀏覽器,但沒有觸發特定的URL,例如「http://www.ABC.com 「或特定項目‘http://www.ABC.com/image/background.jpg’

回答

7

時調用下載圖像您的應用程序,你應該探索鏈接:

Intent intent = getIntent(); 
    String link = intent.getDataString(); 
2

見其他有用的一數據標記的屬性(pathPattern,pathPrefix)在這裏:http://developer.android.com/guide/topics/manifest/data-element.html

+0

鏈接的答案是不歡迎堆棧溢出。 – hims056

+1

@kaviddiss - 歡迎來到StackOverflow,這是一個很好的答案,但對於更多upvotes,你可以擴展一點,也許用問題中的具體例子? SO喜歡有更豐富的答案,而不僅僅是鏈接,謝謝。順便說一句,這裏是一個關於[爲什麼連接不好?]的常見問題(http://meta.stackexchange.com/questions/7515/why-is-linking-bad) –

1

簡單的例子來自意圖過濾器獲取URL:只有

public class openUrl extends Activity{ 

    String link; 
    TextView text; 

    public void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.xmlname); 

     Intent intent = getIntent(); 
      link = intent.getDataString(); 

      text = (TextView)findViewById(R.id.textViewId); 
      text.setText(link.toString()); 
    } 
}