How do I make my android app the default application to open a certain file type?
I tried to clear the defaults but the option is greyed out, does anyone know how to do this?
I want to make my app open with my something.whatever files in android.
You cannot force this, and you shouldn't be able to. What you can do is make known your app can open the filetype. The user gets the standard "what program do you wish to use" dialog, and the user can select something as default.
If the user has allready selected a default, he/she needs to undo that before the dialog appears (obviously, otherwise a 'default' wouldn't have a lot of effect, now would it?)
You can tell the world (aka: android) that you want to open a certain file type by adding an intent-filter. What you basically do is put in your manifest that an activity in your app knows how to handle the filetype (or website/protocol etc). That's quite easy to find, a random question here on SO about the same issue would be: Android intent filter for a particular file extension?
This subject has already been covered here: Register to be default app for custom file type
Add it to you intent-filter:
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
In Android, how to associate file with a different program.
I'm using a "Droid Maxx" with Android Version 4.4.4
How to make a something.html file open with a file editor instead of firefox after you've associated firefox to always be associated with *.html files.
You have to clear out the default setting for the app that has associated with a filetype.
Do this
Go to "Settings". It's in the app list.
Under Device, click "Apps".
Scroll down and click Firefox.
Under the "Launch by default" entry, click "Clear defaults".
Open your something.html file again.
Once again you are presented with a choice with what kind of program you want to open this file with.
If you want to associate and disassociate file types with apps indivdiaully:
There is a third party app called: Default App Manager Lite:
https://play.google.com/store/apps/details?id=com.appiator.defaultappmanager
Then you can run the program and manage your filetype -> default app associations individually.
I think in android every app/activity must have some intent actions and categories in its manifest file. In this intent settings only you have to make your app as default.
Even you write default in manifest, if any other apps found with same intent settings, android system will display all apps with same settings. user has to select one of them, there only it provide one check box to make one app as default for next time onwards. If user didn't check it the list will be displayed every time user opens the file.
I hope it may help you.
Try this
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://"+path),
"application/vnd.android.package-archive");
startActivity(i);
The path variable is your path.
Related
Let me first say I've been reading some similar questions here, for example this one, but was only able to solve my issue partially and still having doubts.
I'm not sure how custom file registration works in Android, I don't know if a new file type can be registered on app install or it can only be done with an intent-filter in the activity that will open the file, and second, I'm not quite sure if there is any possibility to automatically associate your own custom file with your app, or this is something that only the user can do.
That said, I'm creating a custom file type (.aw extension) to be opened with my app and with the next intent-filter I can open the file from the file explorer -for example- in my Android 9 Huawei, but it's not working at all with other devices, like my old Android 5 tablet (which says "Cannot open file" on file click) or my friend Android 9 Samsung. I said that solved "partially" because it appears not to be a universal working intent-filter.
How can I find a "all Android versions" working way of registering a custom file type and let me know if there is any possibility that registration is automatically done so whenever you see a .aw file in explorer -or wherever- your icon appears and your app opens the file.
This is my intent-filter in manifest.xml
<intent-filter
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="application/aw"
android:scheme="content" />
</intent-filter>
And this is how I treat it in activity that will open the file:
private String[] getIntentExtras()
{
Intent intent = getIntent();
String fileContents = null;
String action = intent.getAction();
if(action!=null)
{
if (action.equals(Intent.ACTION_VIEW))
{
fileContents = AWImport.importData(intent);
if (fileContents.startsWith("whatever"))
{
fileContents = fileContents.replace("whatever", "");
}
else
{
showErrorOpeningFile();
return null;
}
}
}
else
...
I'm not sure how custom file registration works in Android
It has never worked especially well, and it is nearly pointless on modern versions of Android. Make sure that you have other ways for the user to choose content for use in your app, such as an "open" toolbar button that triggers an ACTION_OPEN_DOCUMENT Intent.
I don't know if a new file type can be registered on app install or it can only be done with an intent-filter in the activity that will open the file
It can only be done with an <intent-filter>. That typically goes on the <activity> that will handle the Intent. It could go on an <activity-alias> that you enable/disable separately, if there is some need for this.
I'm not quite sure if there is any possibility to autommatically associate your own custom file with your app, or this is something that only the user can do
Having the <intent-filter> is automatic. Few apps will be creating a matching Intent, though.
I can open the file from the file explorer -for example- in my Android 9 Huawei
Presumably, that is a bug in that device. Approximately zero apps written in human history will know about your unofficial (and arguably invalid) application/aw MIME type to create an Intent that uses it.
How can I find a "all Android versions" working way of registering a custom file type
There is none.
whenever you see a .aw file in explorer -or wherever- your icon appears and your app opens the file
There is no guaranteed way to do this. How a file explorer handles files is up to the developers of the file explorer, not you. Many will only work for common and popular MIME types, not others.
You are welcome to add an <intent-filter> using pathPattern to try to match literally on file extensions. Since a Uri does not have to have a file extension, this will not work in all cases, but it will work for some users and some file explorers.
In general, consider this form of getting content to your app to be an additional feature, usable by a small percentage of your users. Focus primarily on something else, such as ACTION_OPEN_DOCUMENT, that will work for everyone.
I am new in android and I have develop an application in android but the issue is when i install it on my device it shows me 2 icons one is working and other one says that receipt organizer has been stopped unexpectedly.Kindly let me know how i can get out of this rid ?Is it some kind of code error or problem in the manifest or properties ?Also one more question now my api level is set to 18 if i set it to previous version then the functionality will not get disturbed right ?So let me know if any one can help.
Look at your manifest file. Your manifest file should have only one activity that has the LAUNCHER in the intent filter.
Choose your main activity (which should have this intent filter), and delete the intent filters from the other activity. after that, you should see only one application icon.
As illustrated by a number of questions here, it's sometimes difficult to get intent filters configured correctly. If a filter is not working like expected (e.g., app shows "permission denied"), what are some tricks to figure out why?
Update: To clarify, I'm not just talking about built-in intents. It's been a struggle getting a custom OAuth callback URL to resolve to the correct activity, but I can't tell if the issue is due to my intent filter or something else.
Option 1: Catch-all IntentFilter, then debug IntentFilter.match()
I wanted to ask exactly the same question. I know of no readily available tools for debugging failing intent filters but this is the approach I'm thinking of:
Make the intent filter as permissive as possible (i.e. put wildcards everywhere you can) so that you can grab and examine the Intent from within your application
Submit the Intent object thus obtained to your real intent filter's match method. You should be able to tell at which stage matching failed by looking which NO_MATCH_* constant is returned.
Once you captured the Intent you can also run the matching in a debugger so better understand what is wrong.
Option 2: Use the App Links Assistant
(This option only works if you want to debug http/https links)
Make sure the App Links Assistant plugin is enabled (File > Settings > Plugins > check "App Links Assistant" in the list). Restart Studio if prompted
Open the assistant (Tools > App Links Assistant)
Click "Open URL Mapping Editor" button in the side bar
Create/Edit your IntentFilter in the dialog
Type a test url in the "Check URL Mapping" box.
This will not tell you why a filter does not work, but allows much faster trial-and-error testing. That's what allowed me to understand why my filter wouldn't work (turns out we can't put wildcards in the "port". I set scheme to http, host filter to *, left port number empty (tried * as well) and set a pathPattern, but it would only matcĥ port 80 (on arbitrary hosts)
First - check if called component is declared in the parent manifest for the calling component.
If the called component is yours and not in the same app, check if it is declared in its own manifest.
Other possible problem - if the called component is correct by itself (broken layouts, forbidden elements in a widget)
Some intent-filters are protected by the system. And as such would require you to have a permission before you can use it. The trick is to know what you want. Once you know what you want, then you can look up intent filters that are available.
The preferred option would be to learn the traverse the android source code and find what you're looking for in the manifest.
We know how to hide an app in app drawer (launcher) referring to hide one application in application menu of android , however, could we hide app itself within its code? I mean is it possible to remove activity's intent filter
<category android:name="android.intent.category.LAUNCHER" />
dynamically within its code.
No. The manifest is read by the Android package manager system when it is installed. Afterwards, these values are read from it's own datastore and not from the manifest so without modifying the PackageManager or installing a different version of the app, these settings cannot be changed.
AFAIK, this isn't possible. The manifest states what your application can or can't do.
Think about permissions : they are required for proper code execution, but you can't change them once your application is installed. That should be the same for intent filters.
In windows text files are displayed with notepad icon. When we double click the particular file it open’s the notepad and displays the file.
Like that I need to open the file from the download folder in android. I have used the intent-filter for register my ics file’s mime type. When I select the file in the download folder it just opens my application only. At that time I need to open / read the selected file. How to do this? I am new to android Can anyone help me?
You can determine the Intent your activity was fired with by calling getIntent(), and you can access the data for that Intent (in this case, likely a URI), by calling getIntent().getData(). Also, the action is likely ACTION_VIEW, but you probably know this already if you've set up your <intent-filter> properly.
When your application is called, it is supplied an Intent.
You can get the file name from the intent that is supplied to your application and open the file using new FileInputStream(String filename).
You can now read the data from this stream as you normally would in Java.
P.S. Make sure your application has enough permissions to access the file. You may need to declare the required permissions in your manifest.