Register to Be Default App for Custom File Type

Register to be default app for custom file type

I think that you don't choose that. This is handle by the system. Same thing when you send an intent to be handled by a map, If you have skyfire for instance, the system pops up a window an you can choose the application and choose if you want it to always open this kind of file.

Unless of course if your application is the only one to open this kind of file.

Edit
I think if you want your app to say "hey I'm able to open these .cool files", you need to set up <intent-filters> with a tag <data> and specificy the mimeType or Uri. Check here for more details.

How can I set a file association from a custom file type to a program

Basically you have to do this -

In registry add these keys

[HKEY_CURRENT_USER\Software\Classes\dekEditor\shell\open\command]<br/>
@="c:\path\to\app.exe \"%1\""<br/>
[HKEY_CURRENT_USER\Software\Classes\.dek]<br/>
@="dekEditor"<br/>

This is a 2 step task.First you associate your extension .dek with dekEditor (2nd entry) and then specify it in Classes(1st entry).

Answer taken from: Create registry entry to associate file extension with application in C++

MSDN Article.

Change default application for .txt

I guess you want to this because you have some kind of Set as default option in your program, by the way I have spent the last hour trying to figure out why it doesn't work and here it is what I've found so far.

The step you need to take are the following:

  • Creates a registry key in ClassesRoot for the .custom extension.
    (Period is important)

Code:

Registry.ClassesRoot.CreateSubKey(".custom").SetValue("", "customfile", Microsoft.Win32.RegistryValueKind.String);`
  • Creating the "Customfile" sub-key and the "customfile\open\command"
    subkey that is needed to store the path to the application that will
    open this file type.

Code:

Registry.ClassesRoot.CreateSubKey("Customfile\shell\open\command").SetValue("", PATH_TO_YOUR_EXE, Microsoft.Win32.RegistryValueKind.String);

And now the association has been made, your app will be registered as one of those which can open that extention.



The case of .txt (or other already associated extentions)

After messing a little bit around i found out that in order to do changes to an already associated extention you also need to edit the registry

Example (with .txt ext.)

 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice

This key has an ProgId value which actually contains the default application set by the user, the value is a string. So you will also have do edit/delete this Registry as well.

I hope it helps :)!

Register new file type/extension on app install/open

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.

How to make a C# Application work as the default program for certain files?

I did this recently, though I used a different action, not the default Open action.

First you find out file type of some extension, say .jpg:

var imgKey = Registry.ClassesRoot.OpenSubKey(".jpg")
var imgType = key.GetValue("");

Then you find out the path to your executable and build the "command string":

String myExecutable = Assembly.GetEntryAssembly().Location;
String command = "\"" + myExecutable + "\"" + " \"%1\"";

And register your executable to open files of that type:

String keyName = imgType + @"\shell\Open\command";
using (var key = Registry.ClassesRoot.CreateSubKey(keyName)) {
key.SetValue("", command);
}

How to set the default program for a file extension?

You should edit your registry:
e.g.

Or you should create an installer project and set the appropriate configuration.



Related Topics



Leave a reply



Submit