2011-08-02 139 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()); 
    } 
}