Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / templates / articles / app_intents.html
blob290399988cac55246a3b1ce27bd3d9eae4591ea7
1 <h1>Connect Apps with Web Intents</h1>
3 <p class="warning">
4 <b>Warning: </b>
5 Deprecated in Chrome 24.
6 Web intents are no longer supported.
7 </p>
9 <p>
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.
16 </p>
18 <p>Chrome Apps use Web Intents as their primary mechanism for inter-app
19 communication.</p>
21 <p class="note">
22 <b>API Samples: </b>
23 Want to play with the code?
24 Check out the
25 <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/webintents">webintents</a> sample.
26 </p>
28 <h2 id="register">Register your app to handle an action</h2>
30 <p class="warning">
31 <b>Warning: </b>
32 Deprecated in Chrome 24.
33 Web intents are no longer supported.
34 </p>
36 <p>
37 You must supply the intent in the manifest:
38 </p>
40 <pre data-filename="manifest.json">
41 "intents":{
42 "http://webintents.org/edit" : [{
43 "title" : "Best Image editing app",
44 "type" : ["image/*"]
47 </pre>
49 <p>
50 Unlike extensions and hosted apps, Chrome applications do not
51 need a "href" attribute in the manifest declaration, this is
52 because Chrome Apps have a single entry point for
53 launch - the <code>onLaunched</code> event.
54 </p>
56 <h2 id="content">Handling content types</h2>
58 <p class="warning">
59 <b>Warning: </b>
60 Deprecated in Chrome 24.
61 Web intents are no longer supported.
62 </p>
64 <p>
65 Your application can be the user's preferred choice for handling a file type.
66 For example, your application could handle viewing images or viewing pdfs.
67 You must supply the intent in the manifest
68 and use the "http://webintents.org/view" action:
69 </p>
70 <p>To be able declare your application's ability to view RSS and ATOM
71 feeds, you would add the following to your manifest.
72 </p>
73 <pre data-filename="manifest.json">
74 "intents": {
75 "http://webintents.org/view" : [{
76 "title" : "RSS Feed Reader",
77 "type" : ["application/atom+xml", "application/rss+xml"]
80 </pre>
82 <p>
83 Your application will receive intent payload through the <code>onLaunched</code> event.
84 </p>
85 <pre>
86 chrome.app.runtime.onLaunched(function(intent) {
87 // App Launched
88 if(intent.action == "http://webinents.org/view" &amp;&amp;
89 intent.type == "application/atom+xml") {
91 // obtain the ATOM feed data.
92 var data = intent.data;
94 });
95 </pre>
97 <h2 id="launching">Launching an app with a file</h2>
99 <p class="warning">
100 <b>Warning: </b>
101 Deprecated in Chrome 24.
102 Web intents are no longer supported.
103 </p>
106 If your app handles the <code>view</code> intent,
107 it is possible to launch it from the command line with a file as a parameter.
108 </p>
109 <pre>
110 chrome.exe --app-id [app_id] [path_to_file]
111 </pre>
113 This will implicity launch your application with an intent payload populated
114 with the action set to "http://webintents.org/view", the type set to the
115 mime-type of the file and the data as a <code>FileEntry</code> object.
116 </p>
117 <pre>
118 chrome.app.runtime.onLaunched(function(intent) {
119 // App Launched
120 var data = intent.data;
122 </pre>
124 <h2 id="launching">Manipulating the file</h2>
126 <p class="warning">
127 <b>Warning: </b>
128 Deprecated in Chrome 24.
129 Web intents are no longer supported.
130 </p>
133 When your application is launched with a file as the parameter
134 on the command-line,
135 the <code>intent.data</code> property is a <code>FileEntry</code>.
136 This is really cool because now you have a direct reference back to the physical
137 file on the disk,
138 and you can write data back to it.
139 </p>
141 <pre>
142 chrome.app.runtime.onLaunched(function(intent) {
143 // App Launched
144 var data = intent.data;
145 if(data instanceof FileEntry) {
146 data.createWriter(function(writer) {
147 writer.onwriteend = function(e) {
148 console.log('Write completed.');
151 writer.onerror = function(e) {
152 console.log('Write failed: ' + e.toString());
155 // Create a new Blob and write it to log.txt.
156 var blob = new Blob(['Lorem Ipsum'], {type: 'text/plain'});
157 writer.write(blob);
161 </pre>
163 <h2 id="return">Returning data to calling application</h2>
165 <p class="warning">
166 <b>Warning: </b>
167 Deprecated in Chrome 24.
168 Web intents are no longer supported.
169 </p>
172 Lots of applications want to cooperate
173 with the app that invoked them.
174 It's easy to send data back to the calling client
175 using <code>intent.postResult</code>:
176 </p>
178 <pre>
179 chrome.app.runtime.onLaunched(function(intent) {
180 // App Launched
181 console.log(intent.action);
182 console.log(intent.type);
183 var data = intent.data;
184 // Do something with the data;
186 intent.postResult(newData);
188 </pre>
190 <h2 id="localize">Localizing your app title</h2>
192 <p class="warning">
193 <b>Warning: </b>
194 Deprecated in Chrome 24.
195 Web intents are no longer supported.
196 </p>
199 If your application or extension is localized
200 as per the guidelines in
201 <a href="i18n.html">Internationalization (i18n)</a>,
202 you can localize the title of your intent in the picker
203 using the exact same infrastructure:
204 </p>
206 <pre data-filename="manifest.json">
207 "intents": {
208 "http://webintents.org/edit" : [{
209 "title" : "__MSG_intent_title__",
210 "type" : ["image/*"],
211 "disposition" : "inline"
214 </pre>
216 <h2 id="invoke">Invoking an action</h2>
218 <p class="warning">
219 <b>Warning: </b>
220 Deprecated in Chrome 24.
221 Web intents are no longer supported.
222 </p>
225 If your application needs to be able
226 to use the functionality of another application,
227 it can simply ask the browser for it.
228 To ask for an application that supports image editing,
229 it's as simple as:
230 </p>
232 <pre>
233 var intent = new WebKitIntent("http://webintents.org/edit", "image/png", "dataUri://");
235 window.navigator.webkitStartActivity(intent, function(data) {
236 // The data from the remote application is returned here.
238 </pre>
240 <h2 id="errors">Handling Errors and Exceptions</h2>
242 <p class="warning">
243 <b>Warning: </b>
244 Deprecated in Chrome 24.
245 Web intents are no longer supported.
246 </p>
249 If your service application needs to signal to the client application
250 that an unrecoverable error has occurred,
251 then your application will need
252 to call <code>postError</code> on the intent object.
253 This will signal to the client’s onError callback
254 that something has gone wrong.
255 </p>
257 <h3 id="client">Client</h3>
259 <pre>
260 var intent = new WebKitIntent("http://webintents.org/edit", "image/png", "dataUri://");
262 var onSuccess = function(data) {};
263 var onError = function() {};
265 window.navigator.webkitStartActivity(intent, onSuccess, onError);
266 </pre>
268 <h3 id="service">Service</h3>
269 <pre>
270 chrome.app.runtime.onLaunched(function(intent) {
271 // App Launched
272 console.log(intent.action);
273 console.log(intent.type);
274 var data = intent.data;
275 // Do something with the data;
277 intent.postResult(newData);
279 </pre>
281 <p class="backtotop"><a href="#top">Back to top</a></p>