Issue with intent filter for opening a file in Android app

后端 未结 1 1452
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 13:31

I\'m trying to open any file with a .conf extension in my android app. Here\'s what I have in my AndroidManifest.xml:



        
相关标签:
1条回答
  • 2020-12-21 14:16

    Remove:

    <data android:host="*" />
    

    from both <intent-filter> entries and:

    <data android:pathPattern=".*\\.conf" />
    

    from the content one.

    File extensions are not used much on Android. Starting with Android Q, files are not used much on Android. There is no requirement for a ContentProvider to put a file-like extension on a content Uri, as you can see from the Uri in your screenshot.

    If you wish to support common Intent actions like ACTION_VIEW, your best bet is to save the file in a common meta-format (e.g., JSON, XML) with a file extension that matches, then have your <intent-filter> filter on the corresponding MIME type. You will need to deal with the possibility that the user chooses a file that was not created by your app, though technically you need to deal with that even with your custom extension.

    0 讨论(0)
提交回复
热议问题