1 <h1>Connect Apps with Web Intents
</h1>
5 Deprecated in Chrome
24.
6 Web intents are no longer supported.
10 <a href=
"http://webintents.org/">Web Intents
</a>
11 allow your application to quickly communicate
12 with other applications on the user's system and inside their browser.
13 Your application can register to handle specific user actions
14 such as editing images via the
<code>manifest.json
</code>;
15 your application can also invoke actions to be handled by other applications.
18 <p>Chrome Apps use Web Intents as their primary mechanism for inter-app
21 <h2 id=
"register">Register your app to handle an action
</h2>
25 Deprecated in Chrome
24.
26 Web intents are no longer supported.
30 You must supply the intent in the manifest:
33 <pre data-filename=
"manifest.json">
35 "http://webintents.org/edit" : [{
36 "title" :
"Best Image editing app",
43 Unlike extensions and hosted apps, Chrome applications do not
44 need a
"href" attribute in the manifest declaration, this is
45 because Chrome Apps have a single entry point for
46 launch - the
<code>onLaunched
</code> event.
49 <h2 id=
"content">Handling content types
</h2>
53 Deprecated in Chrome
24.
54 Web intents are no longer supported.
58 Your application can be the user's preferred choice for handling a file type.
59 For example, your application could handle viewing images or viewing pdfs.
60 You must supply the intent in the manifest
61 and use the
"http://webintents.org/view" action:
63 <p>To be able declare your application's ability to view RSS and ATOM
64 feeds, you would add the following to your manifest.
66 <pre data-filename=
"manifest.json">
68 "http://webintents.org/view" : [{
69 "title" :
"RSS Feed Reader",
70 "type" : [
"application/atom+xml",
"application/rss+xml"]
76 Your application will receive intent payload through the
<code>onLaunched
</code> event.
79 chrome.app.runtime.onLaunched(function(intent) {
81 if(intent.action ==
"http://webinents.org/view" &&
82 intent.type ==
"application/atom+xml") {
84 // obtain the ATOM feed data.
85 var data = intent.data;
90 <h2 id=
"launching">Launching an app with a file
</h2>
94 Deprecated in Chrome
24.
95 Web intents are no longer supported.
99 If your app handles the
<code>view
</code> intent,
100 it is possible to launch it from the command line with a file as a parameter.
103 chrome.exe --app-id [app_id] [path_to_file]
106 This will implicity launch your application with an intent payload populated
107 with the action set to
"http://webintents.org/view", the type set to the
108 mime-type of the file and the data as a
<code>FileEntry
</code> object.
111 chrome.app.runtime.onLaunched(function(intent) {
113 var data = intent.data;
117 <h2 id=
"launching">Manipulating the file
</h2>
121 Deprecated in Chrome
24.
122 Web intents are no longer supported.
126 When your application is launched with a file as the parameter
128 the
<code>intent.data
</code> property is a
<code>FileEntry
</code>.
129 This is really cool because now you have a direct reference back to the physical
131 and you can write data back to it.
135 chrome.app.runtime.onLaunched(function(intent) {
137 var data = intent.data;
138 if(data instanceof FileEntry) {
139 data.createWriter(function(writer) {
140 writer.onwriteend = function(e) {
141 console.log('Write completed.');
144 writer.onerror = function(e) {
145 console.log('Write failed: ' + e.toString());
148 // Create a new Blob and write it to log.txt.
149 var blob = new Blob(['Lorem Ipsum'], {type: 'text/plain'});
156 <h2 id=
"return">Returning data to calling application
</h2>
160 Deprecated in Chrome
24.
161 Web intents are no longer supported.
165 Lots of applications want to cooperate
166 with the app that invoked them.
167 It's easy to send data back to the calling client
168 using
<code>intent.postResult
</code>:
172 chrome.app.runtime.onLaunched(function(intent) {
174 console.log(intent.action);
175 console.log(intent.type);
176 var data = intent.data;
177 // Do something with the data;
179 intent.postResult(newData);
183 <h2 id=
"localize">Localizing your app title
</h2>
187 Deprecated in Chrome
24.
188 Web intents are no longer supported.
192 If your application or extension is localized
193 as per the guidelines in
194 <a href=
"i18n">Internationalization (i18n)
</a>,
195 you can localize the title of your intent in the picker
196 using the exact same infrastructure:
199 <pre data-filename=
"manifest.json">
201 "http://webintents.org/edit" : [{
202 "title" :
"__MSG_intent_title__",
203 "type" : [
"image/*"],
204 "disposition" :
"inline"
209 <h2 id=
"invoke">Invoking an action
</h2>
213 Deprecated in Chrome
24.
214 Web intents are no longer supported.
218 If your application needs to be able
219 to use the functionality of another application,
220 it can simply ask the browser for it.
221 To ask for an application that supports image editing,
226 var intent = new WebKitIntent(
"http://webintents.org/edit",
"image/png",
"dataUri://");
228 window.navigator.webkitStartActivity(intent, function(data) {
229 // The data from the remote application is returned here.
233 <h2 id=
"errors">Handling Errors and Exceptions
</h2>
237 Deprecated in Chrome
24.
238 Web intents are no longer supported.
242 If your service application needs to signal to the client application
243 that an unrecoverable error has occurred,
244 then your application will need
245 to call
<code>postError
</code> on the intent object.
246 This will signal to the client’s onError callback
247 that something has gone wrong.
250 <h3 id=
"client">Client
</h3>
253 var intent = new WebKitIntent(
"http://webintents.org/edit",
"image/png",
"dataUri://");
255 var onSuccess = function(data) {};
256 var onError = function() {};
258 window.navigator.webkitStartActivity(intent, onSuccess, onError);
261 <h3 id=
"service">Service
</h3>
263 chrome.app.runtime.onLaunched(function(intent) {
265 console.log(intent.action);
266 console.log(intent.type);
267 var data = intent.data;
268 // Do something with the data;
270 intent.postResult(newData);
274 <p class=
"backtotop"><a href=
"#top">Back to top
</a></p>