I'm making a custom application and I need to enable it to use it as a file picker (like Drive, and Fotografias, Solid Explorer in the attached screenshot)
I want to open one of my app activities in order to use it as a custom signature pad
My plan is to allow the user to sign and that whould be returned to the file input of the caller application
Currently I have a deeplink that allows me to open the signature activity, the signature is saved in the filesystem of the phone, and after that the user has to use the file explorer to select the signature
Use Intent-filter for this purpose:
Read here: https://developer.android.com/guide/components/intents-filters
<activity android:name="com.yourapp.MainActivity">
<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=".*\\.your_file_extension" />
<data android:host="*" />
</intent-filter>
</activity>
Related
In my project I want to my app to open custom file extension like '.bla'
I used the following IntentFilter to do this:
<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:scheme="content" />
<data android:mimeType="application/*" />
<data android:host="*" />
<data android:pathPattern=".*" />
</intent-filter>
This works great but the problem is my app appears in the 'open with' list for any file type -as expected, but I want it to open just my extension.
I can't use explicit extension '.bla' because it wont work if I open a bla file from WhatsApp, because the file wont have its ordinary path with the extension at the end, instead, it will be some kind like 'content://com.whatsapp.provider.media/item/03fda30df57e-c5e3a-46ea-6df67-fd23e4a3cb4fe'
so, I used the pathPattern as .* instead of something like .*\\.bla to make it work
What shall I do to solve this problem and to make my app opens only the .bla extension only
When user type the url to my .someExt file in his web browser (on Android Phone), the message appears:
This content is unsupported content. Do you really want to download?
Instead, I would like to associate the .someExt (my custom file extension) with my Android Application (that the user has downloaded previously) so when user type the url to .someExt in browser my Application will open the file.
How to achieve it? I guess it has to be done with manifest and some "handle" method in my Activity.
Based on: Associate App with file extension - Intent filter Not working?
I have used:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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="application/someExt" />
</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="*" />
<data android:scheme="file" />
<data android:scheme="smb" />
<data android:scheme="content" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.someExt" />
</intent-filter>
</activity>
Now, when user type the url to my .someExt the file is being downloaded and I can open it when downloading is done (so my Application will run it). But I don't want all those additional clicks - I want it to be:
User click the link to .someExt on the website.
The .someExt opens in my Android Application.
And not the:
User click the link to .someExt on the website.
The file starts to download.
User open "downloads" and click on downloaded file.
The .someExt opens in my Android Application.
I don't think you can realize this feature in Android with different kind of browsers. The URL user type is handled by the browser most of the time. How to deal with the scheme is decided by the behaviors of the browser. If your scheme is http, the browser will try to open with it own and handle by itself.
Currently, most browsers add support for market scheme. If the URI's scheme is market, it will jump to Google Play or other markets.
But is can be done from other app with Intent.
Declare your activity like following to receive the ACTION_VIEW action.
<activity
android:name=".MainActivity2Activity"
android:label="#string/title_activity_main_activity2">
<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:host="com.example.myapp"
android:mimeType="*/*"
android:pathPattern=".*\\.someExt"
android:scheme="http" />
</intent-filter>
</activity>
From other apps, you could do like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://com.example.myapp/test.someExt"), "*/*");
intent.setPackage("com.example.myapplication");
startActivity(intent);
I am writing the application to open HTML files. In some devices (like Galaxy player,nexus one) when i try to open html file from Email client ,my application is not showing in
"open with"
open with " dialog ,but if i open the same HTML file from Gmail client my app is showing in
"open with "
open with" dialog . In other devices(like Google nexus ,S2 etc), i am able to open the HTML file through my application from Email client, Email client .is this device specific issue?
In some devices Email client is not opening the app with mime type as text/html.so i changed like follows.
<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/html"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Then email app is able to show my application in the list.but it will show when we tring to opne HTML/Text files.
If your app opens .HTML files, the intent filter should look something like this:
<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:pathPattern=".*\\.html" />
<data android:mimeType="*/*" />
<data android:scheme="file" />
<data android:host="*" />
</intent-filter>
I have written the below intent filter to open a text file using my app. It seems to work but only sometimes. For example, if I email a text file, if I choose open from mail, my app is not shown. If I choose save first, then open, my app will be shown. Similar experience with drop box, if I try to open from drop box, my app won't be listed as being able to open but if I export from drop box to sd and use a file manager to open it, my app is listed and works.
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</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=".*\\.txt" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.txt" />
<!-- <data android:scheme="content" android:host="*" android:pathPattern=".*\\.txt" /> -->
<data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.txt" />
</intent-filter>
Dropbox and the Email app probably use content providers and don't match the pathPattern. Typically content providers don't include a file extension, but would use the mime type to indicate what type of file is being opened. If you are intending to open any text/plain file, and not necessarily only those which have the .txt extension, then you'd be better off leaving the pathPattern off altogether.
<intent-filter>
<data android:mimeType="text/plain" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Probably beacuse the email app and dropbox uses a different scheme instead of file, http, or https. Try using the mime type attribute only.
EDIT: Acording to the dropbox forums:
FYI, the easiest way to do this now is to open up your app from Dropbox by registering for VIEW with the correct mime-type. Then everything is handed off properly, and saving & watching file changes to re-upload is handled well.
You only have to specify the mime type, and nothing else. I haven't tried this though, but probably this works for the email app as well, as long as the mime types match.
Here is the link if you are interested:
https://forums.dropbox.com/topic.php?id=26035#post-162963
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.xyz" />
</intent-filter>
When I click on somefile.xyz it opens an Intent chooser which contains app's in which I have declaired above intent-filter(.xyz custom file type).But this works when file is in sdcard and I click on it.
How can i make this work for a file as an attachment because the problem is android is not allowing me to download unknown file types from email.