Search code examples
androidandroid-intentintentfilter

How create file to match custom intent filter to open my app?


I've read thousands of questions on this topic but did not find any useful answer.

I have to create a file (containing string) that clicks on it from the downloads app or the file manager i want to open my app. (just my app)

i can create file as needs: file name, file extension or mime tipe

Every attempt made failed: or my app intercepted any file or my app did not intercept my file

so, my questions is:

1) how to create file as needs?

2) how to create intent filter for that file?

thz so much


Solution

  • Sometimes android sdk is not well done, this is a case:

    Using Nexus 6p with Stock 7.1.2 the click on downloaded file generate differente intent base on from app you are. I underline the fact that device has no external app and firmware are stock. Below the list of intent generated by different system apps

    From Donwnloads

    act=android.provider.action.MANAGE_DOCUMENT
    dat=content://com.android.providers.downloads.documents/document/152
    cmp=com.android.providers.downloads.ui/.TrampolineActivity
    

    From Recent (inside Downloads)

    act=android.intent.action.VIEW
    dat=content://com.android.providers.downloads.documents/document/152
    typ=application/json
    

    From official android File explorer (inside Settings)

    act=android.intent.action.VIEW
    dat=content://com.android.externalstorage.documents/document/primary:Download/20-conversation.nc
    typ=application/octet-stream
    

    The only solution I found to intercept all the intent was this (my file is xxxx.nc and contains a json string):

    <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:host="*"
            android:mimeType="*/*"
            android:pathPattern=".*\\.nc"
            android:scheme="content"/>
    </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:host="*"
            android:mimeType="application/json"
            android:scheme="content"/>
    </intent-filter>
    

    I hope third-party file managers do not create more entropy