I created an Audio player app and set it to be my default app for opening audio files.
Now when I click an audio file from filemanager, it opens my app, or rather the activity for receiving the audio file.
But I don't want it that way, I want a custom view from my app to be displayed on the filemanager app just like the image below
The app that does this is YT Music. And I noticed, it's not done with the Android WindowManager because I disabled the Draw over apps on the YT Music app but it's still popping up the view
Can anyone give me a clue of how it's done?
Just like I said, I have a custom view which I want to display on the filemanager when an audio file is clicked and if there's a code, it should be in Java
So after some research, I got what I was looking for...
First, it's just a normal activity displayed like a Dialog box.
I created an activity (DialogBoxActivity.java) and gave it a dialog theme in the AndroidManifest.xml
AndroidManifest.xml
<activity
android:name=".DialogBoxActivity"
android:exported="true"
android:excludeFromRecents="true"
android:theme="#style/DialogBoxTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</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" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</intent-filter>
<intent-filter android:priority="-1">
<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" />
<data android:mimeType="audio/*" />
<data android:mimeType="application/ogg" />
<data android:mimeType="application/x-ogg" />
<data android:mimeType="application/itunes" />
</intent-filter>
</activity>
values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DialogBoxTheme" parent="#style/Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="background">#color/transparent</item>
</style>
</resources>
Related
I am trying to let my app share and handle custom file extension and upon clicking it, it will open my app then I parse it.
I have looked into different ways like LIKE THIS for example and THIS, but clicking on the file from FileBrowser or WhatsApp for example is not detecting my app.
I am using the navigation component if it helps
I am not sure what I am doing wrong, I would appreciate it if someone have a working example.
Thanks.
This is some of the code I tried (I am testing with txt as it is an easy extension) (1)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<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:host="*" />
<data android:pathPattern="*.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<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/txt" />
</intent-filter>
I also tried (2)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.txt"
android:scheme="file" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<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:scheme="content" />
<data android:mimeType="*/*" />
<!--
Work around Android's ugly primitive PatternMatcher
implementation that can't cope with finding a . early in
the path unless it's explicitly matched.
-->
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.txt" />
<!-- keep going if you need more -->
</intent-filter>
and (3)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="text/plain" />
</intent-filter>
I finally my issue, I was testing multiple things at the same time.
I ended up using
<!-- this is needed for apps like whatsapp, it doesn't provide extension, so you can't add path -->
<intent-filter>
<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:mimeType="application/octet-stream"
android:scheme="content" />
</intent-filter>
<!-- this is needed for apps like explorer -->
<intent-filter>
<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="*"
android:mimeType="*/*"
android:pathPattern=".*\\.ext"
android:scheme="content" />
</intent-filter>
If you use mimeType="*/* then check logcat (no filter at all), search for content:// then you see what is the Android sending to your app, then modify the IntentFilter to match what you want. Some apps don't send the extension so using pathPattern was not working with it, Also using schema = content is needed
Thanks #CommonsWare for the help.
My app has an activity for opening YouTube links, with intent filters which I've copied from NewPipe. It works fine: when I click on a YouTube link, Android asks me which app to use, and my application appears in the list. The problem is, it asks me this every time, even after I go to the settings and select "Open in this app".
NewPipe works as expected: after choosing "Open in this app", it's used to open YouTube links every time, without asking.
Here's the AndroidManifest portion for my activity, copied from here:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<!-- Youtube filter, copied from NewPipe -->
<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" />
<data android:scheme="https" />
<data android:host="youtube.com" />
<data android:host="m.youtube.com" />
<data android:host="www.youtube.com" />
<data android:host="music.youtube.com" />
<!-- video prefix -->
<data android:pathPrefix="/v/" />
<data android:pathPrefix="/embed/" />
<data android:pathPrefix="/watch" />
<data android:pathPrefix="/attribution_link" />
<!-- channel prefix -->
<data android:pathPrefix="/channel/" />
<data android:pathPrefix="/user/" />
<data android:pathPrefix="/c/" />
</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" />
<data android:scheme="https" />
<data android:host="youtu.be" />
<data android:pathPrefix="/" />
</intent-filter>
</activity>
I haven't done any tests to conclusively answer this, but I think in my case this was because my app didn't have a "main activity". I've added a proper activity with categories LAUNCHER and DEFAULT and now the app behaves as I expect.
This could be a security feature, to prevent "hidden" apps from hijacking somebody's intents.
I would like to make an activity be an option to open .json files type. For example, when I click on a .json file in my explorer, I want it to be opened (or to have an option to open it) in this activity. To achieve this, I have tried to add a pathPattern, a scheme and a host to my activity in the manifest. No success. The explorer says "No application to open this file." After searching on StackOverflow, I tried to add mimeType. Still no success. I've tried over 20 different answers from existing StackOverflow questions, without any success. Here's some of the answers I've tried: here, here, here.
Here's my activity:
<activity
android:name=".JsonActivity"
android:label="Json">
<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" />
<data android:scheme="https" />
<data android:scheme="content" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.json" />
</intent-filter>
</activity>
What am I doing wrong? I made sure I added the WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions and also the category BROWSABLE and the action VIEW.
You need multiple intent filters to address different situation you want to handle.
Example 1, handle http requests without mimetypes:
<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=".*\\.json" />
</intent-filter>
Handle with mimetypes, where the suffix is irrelevant:
<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/json" />
</intent-filter>
Handle intent from a file browser app:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />`enter code here`
<data android:host="*" />
<data android:pathPattern=".*\\.json" />
</intent-filter>
YouTube App for tablets has a sharing-option. For example: I watch a video in the YouTube app and click the button to share. Bluetooth, Googlemail, and Dropbox appear for me. I wonder how i can list my app there? Which intent-filter has my app to have?
Here i have tried. But this is not working for me. I am using Android Kitkat version.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="audio/*" />
<data android:mimeType="video/*" />
<data android:mimeType="text/*" />
<data android:scheme="content" />
<data android:scheme="file" />
</intent-filter>
You have to put this intent filter inside an Activity tag in your Manifest file...
<intent-filter>
<action
android:name="android.intent.action.SEND" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="image/*" /> /* WRITE THE CORRECT TYPE */
</intent-filter>
Then you have to develop the way your Activity handles the data from the current intent.
I have a android application to preview .dst file type,i am able launch the app by clicking on file from the file explorer i did it by following code
<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="*/*" />
<data android:pathPattern=".*\\.DST" />
<data android:host="*" />
</intent-filter>
now i need to launch the app from the default gmail app,i think i need to change the
android:scheme="file"
tag ,please help me with the proper scheme for gmail application..
update the manifest as below
<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="*" />
<data android:mimeType="application/octet-stream"
/>
<data android:pathPattern=".*\\.DST" />
</intent-filter>