开发者

android: problem setting up intent filter to fire off activity when downloading file from web in browser

开发者 https://www.devze.com 2023-02-24 02:10 出处:网络
I am having a problem getting an activity to be initiated in response to a file download from a browser window.

I am having a problem getting an activity to be initiated in response to a file download from a browser window.

When I click the file download button in broswer it gets downloaded to SD card, rather than firing off my MainActivity (or even prompting what I should do with it).

If I then locate the file on the SD card using a file explorer and select it then my MainActivity is initiated.

Have I misunderstood how intent filters work? I have verified the mime type for the download file using wireshark on a pc to verify that it is as expected.

[ If i remove the PathPattern and simply have the mime type in place then when pressing the download button I am prompted saying that there is nothing on the device to handle this file and do I still want to go ahead with the download.]

Any help would be appreciated.

Here is the entry from my manifest:

 <activity android:name=".activity.main.MainActivity"
           android:label="@string/app_name">

     <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="andr开发者_如何学运维oid.intent.category.LAUNCHER" />
     </intent-filter>

     <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="application/xml-mydata" 
              android:pathPattern=".*\\.mydata" />
     </intent-filter>
  </activity>


Conceptually what you have seems fine, though I would dump the pathPattern. Here is a sample project demonstrating these sorts of <intent-filter> elements.

I would make sure that your MIME type has valid syntax. I forget off the top of my head if dashes are allowed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号