I want to open my activity if user clicks a specific text file in file browser like deep link.
Here is my code
<activity
android:name=".debug.DebugActivity"
android:label="#string/debug_label"
android:screenOrientation="portrait">
<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:scheme="file" />
<data android:host="*/*" />
<data android:pathPattern =".*\\.txt" />
<data android:host="*" />
</intent-filter>
</activity>
How can I do that?
Thanks in Advance
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="text/html" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml" />
</intent-filter>
I got the solution with this
Related
I'm trying to let user have the option to open pdf files through my app.
So, when a user clicks on a pdf file from the file manager they should have the option to open it with my app along with other pdf reader apps if available in their device.
I've added the following intent filters in the manifest by scouring through various answer here. They seem to work below Api 29 (my app shows in the list upon clicking a pdf file). But for API Q the app isn't showing on the list.
Intents filters:
<!--For pdf-->
<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:scheme="content"
android:host="*"
android:pathPattern=".*\\.pdf"
android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.pdf"
android:scheme="file" />
</intent-filter>
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\.pdf" />
<data android:pathPattern=".*\\.pdf" />
<data android:scheme="content" />
</intent-filter>
<!--end pdf-->
How can I allow pdf files to be opened with my app in Android Q and above too?
PS: All necessary permissions are taken
I'm using this code for this
<activity
android:name=".OpenPdfActivity"
android:theme="#style/OpenPdfActTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/pdf"
android:scheme="file" />
<data
android:mimeType="application/pdf"
android:scheme="content" />
</intent-filter>
</activity>
I register file extensions in my android video player app in manifest, through following code:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.mp4" />
<data android:pathPattern=".*\\.3gp" />
<data android:pathPattern=".*\\.mkv" />
<data android:pathPattern=".*\\.webm" />
<data android:pathPattern=".*\\.zrp" />
</intent-filter>
This works fine, however when app is installed, shortcut is not created. If I remove this part from manifest, shortcut is created normally:
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
Any ideas on how to accomplish both: register extensions and create shortcut?
I have separated the same code in 2 tags, like this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.mp4" />
<data android:pathPattern=".*\\.3gp" />
<data android:pathPattern=".*\\.mkv" />
<data android:pathPattern=".*\\.webm" />
<data android:pathPattern=".*\\.zrp" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
I'm creating an intent filter for a specific extension (.infi) for my app. It works correctly with ES file explorer & Solid explorer. However when I open the file with Samsung default file explorer (Device Galaxy Tab S2) it shows a strange message "No application to perform this action", on other device (Note 4) it tries to open the file with Adobe Reader with an error message. Here is my code from manifests file :
<activity android:name=".ImportCollections">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.infi" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.infi" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.infi" />
<data android:host="gmail-ls" />
</intent-filter>
</activity>
For future references, I looked for another open source app implementing this feature correctly. These guys are doing a great job:
https://github.com/ankidroid/Anki-Android/blob/develop/AnkiDroid/src/main/AndroidManifest.xml
Here is my code that worked (just replace "infi" with your custom extention)
<activity
android:name=".ImportCollections"
android:launchMode="singleTask"
android:parentActivityName=".ManageCollections">
<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=".*\\.infi"
android:scheme="http" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.infi"
android:scheme="https" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.infi"
android:scheme="content" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.infi"
android:scheme="file" />
</intent-filter>
<!-- MIME type matcher for .infi files coming from providers like gmail which hide the file extension -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/infi" />
<data android:mimeType="application/x-infi" />
<data
android:mimeType="application/octet-stream"
android:scheme="content" />
<data
android:mimeType="application/zip"
android:scheme="content" />
</intent-filter>
</activity>
I want attachment of my email having xls and xlsx file to be opened with my Android App. Currently I am able to open csv file from my app. Please help.
Code I am using in my manifest for csv is :
<intent-filter
android:icon='#drawable/rr_ipad1_icon'
android:label="#string/app_name"
android:priority='1'>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/csv" />
<data android:pathPattern="*.csv" />
</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="text/csv" android:scheme="http" android:host="*" android:pathPattern=".*\\.csv" />
<data android:mimeType="text/csv" android:scheme="https" android:host="*" android:pathPattern=".*\\.csv" />
</intent-filter>
Try this
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xls" />
<data android:pathPattern=".*..*..*..*..*..*.xls" />
<data android:pathPattern=".*..*..*..*..*.xls" />
<data android:pathPattern=".*..*..*..*.xls" />
<data android:pathPattern=".*..*..*.xls" />
<data android:pathPattern=".*..*.xls" />
<data android:pathPattern=".*.xls" />
</intent-filter>
and same for xlsx
This question has been asked [numerous times] before, but I have not seen any definitive answers, or examples of code that actually works.
I would like to associate an Activity with a particular file type.
For discussion, assume that I want my Activity to be associated with PDFs.
Here is what I currently have. I have experimented with many different values and combinations of values in the intent-filter, but I have yet to get my Activity to start when a PDF is selected.
<activity name="com.mycompany.MyActivity">
<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:scheme="file" />
<data android:mimeType="application/pdf" />
<data android:pathPattern="\\*\\.pdf" />
<data android:host="*" />
</intent-filter>
</activity>
Does anyone know how to actually make this work?
Have you tried with that simple version :
<activity name="com.mycompany.MyActivity">
<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/pdf" />
</intent-filter>
</activity>
Your pathPattern is definitively wrong and you are restricting it too much with the mimetype.
Try the following:
<activity name="com.mycompany.MyActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
</activity>
To open both local and remote pdf files I'd do:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.pdf" />
</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:scheme="http" android:host="*" android:pathPattern=".*\\.pdf" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.pdf" />
</intent-filter>