Issue
I want to create a simple app that can view PDF files.
To test that I have deleted the default PDF file viewer on the emulator and when I want to open a PDF file the emulator says Can't open that file
.
How can I make my app visible to that implicit intent so it will be used/shown when I click that PDF file?
What <intent-filter>
configuration do I need to add in my manifest.xml
, if any?
Solution
@see javdromero's post
javdromero's approach worked for me after making a few tweaks.
1. Specify the PDF mime type
The mime type for PDF files is application/pdf
so we have to use that:
android:mimeType="application/pdf"
The android:host
attribute can be ignored because we don't take anything from the web and don't have the android:scheme
attribute specified. The same goes for the android:pathPattern
attribute. See the <data>
element's documentation.
That leaves us with an error message Missing URL
and the text is in red.
2. Ignore the Missing URL error
The Missing URL
error concerns the whole <intent-filter>
element because we should specify the android:scheme
attribute there.
But we don't use any schemes so we import the tools
namespace and specify the tools:ignore
attribute:
tools:ignore="AppLinkError"
That leaves us with following <intent-filter>
element configuration:
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/pdf" />
</intent-filter>
Answered By - René Jörg Spies
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.