Difference between revisions of "MimeTypes"

From WebOS Internals
Jump to navigation Jump to search
(Created page with "There is a way that your app can register with LunaSysMgr for opening a specific mime type, URL scheme, or URL pattern, in the app's appinfo. This happens during app install, so ...")
 
Line 1: Line 1:
There is a way that your app can register with LunaSysMgr for opening a specific mime type, URL scheme, or URL pattern, in the app's appinfo. This happens during app install, so you do not have to explicitly call an Luna bus commands.
+
= 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:
 +
 
 +
<pre>
 +
this.controller.serviceRequest("palm://com.palm.applicationManager", {
 +
  method: "open",
 +
  parameters:  {
 +
      target: "the url or resource that you want to open"
 +
  }
 +
});
 +
</pre>
 +
 
 +
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 ==
 +
 
 +
<pre>
 +
"mimeTypes": [
 +
    {"scheme": "maploc"}
 +
]
 +
</pre>
 +
 
 +
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 ==
 +
 
 +
<pre>
 +
"mimeTypes": [
 +
    { "urlPattern": "^https?:" }
 +
]
 +
</pre>
 +
 
 +
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 ==
 +
 
 +
== Extension ==
 +
 
 +
 
 +
= 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

Revision as of 06:37, 19 August 2013

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:

this.controller.serviceRequest("palm://com.palm.applicationManager", {
  method: "open",
  parameters:  {
      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

Extension

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