MimeTypes

From WebOS Internals

Revision as of 05:43, 19 August 2013 by Dkirker (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Intro

There are a couple of methods for registering an app to handle a particular MIME type or extension, URL scheme, or URL redirect.

I (dkirker), personally recommend the appinfo method, as it applies when your app installs, and is the easiest to maintain.

Both methods can be controlled from within the "Default Apps" scene in the "Device Info" app. (Open the "Device Into" app, select the menu, choose "Default Applications". Some patches provide this in other areas.)


BIG IMPORTANT NOTE

Developers SHOULD ALWAYS open URLs to documents and resources through the system manager, and not by calling an app directly. You can do this by calling:


In Mojo:

this.controller.serviceRequest("palm://com.palm.applicationManager", {
  method: "open",
  parameters:  {
      target: "the url or resource that you want to open"
  }
});


In luna-send:

palm://com.palm.applicationManager/open '{"target": "the url or resource that you want to open"}'


This allows the system to determine the user's preferred application. If you call the applicationManager with the "launch" method, you will be stoned to death with a bag full of Veer's. Just sayin'! ;-)


appinfo.json Method

There is a "mimeTypes" keyword that you can use within your appinfo.json file to auto-register your app. When the system receives a URL or file that your app can handle, your app is launched with a launch parameter "target" set to the location of the file.


Scheme

"mimeTypes": [
    {"scheme": "maploc"}
]


LunaSysMgr actually converts this to a URL pattern to a regular expression as follows, and registers that:

"^" + scheme + ":"

So, to register a scheme, just use a value that is the part before the ":" or "://" in a URL.


URL Pattern

"mimeTypes": [
    { "urlPattern": "^https?:" }
]


The value of "urlPattern" is a regular expression to match against the URL that LunaSysMgr is handling. This is a GREAT way to allow apps for services that have a website (say, Instagram, or Twitter, or Google Maps) to launch the app, instead of the website! At the moment, there are no real methods to change this in the "Default Applications" scene (except for the http/https option in the example above, which is under the "Web" setting).


MIME Type

"mimeTypes": [
    { "mime": "text/html", "extension": "html" }
]


This allows you to register for a specific MIME Type and extension. I have not read the code to see if multiple extensions can be defined in the "extensions" property, but you can certainly define multiple instances of the same MIME with different extensions. Example:


"mimeTypes": [
    { "mime": "text/html", "extension": "html" },
    { "mime": "text/html", "extension": "htm" }
]


Luna-bus Method

Implementation

See: (for use) https://github.com/woce/LunaSysMgr/blob/beta/Src/base/application/ApplicationDescription.cpp#L179

See: (for implementation) https://github.com/woce/LunaSysMgr/blob/beta/Src/base/application/MimeSystem.cpp

Personal tools
Google AdSense