OLD | NEW |
1 <h1>Connect Apps with Web Intents</h1> | 1 <h1>Connect Apps with Web Intents</h1> |
2 | 2 |
3 | 3 |
4 <p> | 4 <p> |
5 <a href="http://webintents.org/">Web Intents</a> | 5 <a href="http://webintents.org/">Web Intents</a> |
6 allow your application to quickly communicate | 6 allow your application to quickly communicate |
7 with other applications on the user's system and inside their browser. | 7 with other applications on the user's system and inside their browser. |
8 Your application can register to handle specific user actions | 8 Your application can register to handle specific user actions |
9 such as editing images via the <code>manifest.json</code>; | 9 such as editing images via the <code>manifest.json</code>; |
10 your application can also invoke actions to be handled by other applications. | 10 your application can also invoke actions to be handled by other applications. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 "title" : "RSS Feed Reader", | 59 "title" : "RSS Feed Reader", |
60 "type" : ["application/atom+xml", "application/rss+xml"] | 60 "type" : ["application/atom+xml", "application/rss+xml"] |
61 }] | 61 }] |
62 } | 62 } |
63 </pre> | 63 </pre> |
64 | 64 |
65 <p> | 65 <p> |
66 Your application will receive intent payload through the <code>onLaunched</code>
event. | 66 Your application will receive intent payload through the <code>onLaunched</code>
event. |
67 </p> | 67 </p> |
68 <pre> | 68 <pre> |
69 chrome.experimental.app.onLaunched(function(intent) { | 69 chrome.app.runtime.onLaunched(function(intent) { |
70 // App Launched | 70 // App Launched |
71 if(intent.action == "http://webinents.org/view" && | 71 if(intent.action == "http://webinents.org/view" && |
72 intent.type == "application/atom+xml") { | 72 intent.type == "application/atom+xml") { |
73 | 73 |
74 // obtain the ATOM feed data. | 74 // obtain the ATOM feed data. |
75 var data = intent.data; | 75 var data = intent.data; |
76 } | 76 } |
77 }); | 77 }); |
78 </pre> | 78 </pre> |
79 | 79 |
80 | 80 |
81 <h2 id="launching">Launching an app with a file</h2> | 81 <h2 id="launching">Launching an app with a file</h2> |
82 <p> | 82 <p> |
83 If your app handles the <code>view</code> intent, | 83 If your app handles the <code>view</code> intent, |
84 it is possible to launch it from the command line with a file as a parameter. | 84 it is possible to launch it from the command line with a file as a parameter. |
85 </p> | 85 </p> |
86 <pre> | 86 <pre> |
87 chrome.exe --app-id [app_id] [path_to_file] | 87 chrome.exe --app-id [app_id] [path_to_file] |
88 </pre> | 88 </pre> |
89 <p> | 89 <p> |
90 This will implicity launch your application with an intent payload populated | 90 This will implicity launch your application with an intent payload populated |
91 with the action set to "http://webintents.org/view", the type set to the | 91 with the action set to "http://webintents.org/view", the type set to the |
92 mime-type of the file and the data as a <code>FileEntry</code> object. | 92 mime-type of the file and the data as a <code>FileEntry</code> object. |
93 </p> | 93 </p> |
94 <pre> | 94 <pre> |
95 chrome.experimental.app.onLaunched(function(intent) { | 95 chrome.app.runtime.onLaunched(function(intent) { |
96 // App Launched | 96 // App Launched |
97 var data = intent.data; | 97 var data = intent.data; |
98 }); | 98 }); |
99 </pre> | 99 </pre> |
100 | 100 |
101 <h2 id="launching">Manipulating the file</h2> | 101 <h2 id="launching">Manipulating the file</h2> |
102 <p> | 102 <p> |
103 When your application is launched with a file as the parameter | 103 When your application is launched with a file as the parameter |
104 on the command-line, | 104 on the command-line, |
105 the <code>intent.data</code> property is a <code>FileEntry</code>. | 105 the <code>intent.data</code> property is a <code>FileEntry</code>. |
106 This is really cool because now you have a direct reference back to the physic
al | 106 This is really cool because now you have a direct reference back to the physic
al |
107 file on the disk, | 107 file on the disk, |
108 and you can write data back to it. | 108 and you can write data back to it. |
109 </p> | 109 </p> |
110 | 110 |
111 <pre> | 111 <pre> |
112 chrome.experimental.app.onLaunched(function(intent) { | 112 chrome.app.runtime.onLaunched(function(intent) { |
113 // App Launched | 113 // App Launched |
114 var data = intent.data; | 114 var data = intent.data; |
115 if(data instanceof FileEntry) { | 115 if(data instanceof FileEntry) { |
116 data.createWriter(function(writer) { | 116 data.createWriter(function(writer) { |
117 writer.onwriteend = function(e) { | 117 writer.onwriteend = function(e) { |
118 console.log('Write completed.'); | 118 console.log('Write completed.'); |
119 }; | 119 }; |
120 | 120 |
121 writer.onerror = function(e) { | 121 writer.onerror = function(e) { |
122 console.log('Write failed: ' + e.toString()); | 122 console.log('Write failed: ' + e.toString()); |
(...skipping 10 matching lines...) Expand all Loading... |
133 | 133 |
134 <h2 id="return">Returning data to calling application</h2> | 134 <h2 id="return">Returning data to calling application</h2> |
135 <p> | 135 <p> |
136 Lots of applications want to cooperate | 136 Lots of applications want to cooperate |
137 with the app that invoked them. | 137 with the app that invoked them. |
138 It's easy to send data back to the calling client | 138 It's easy to send data back to the calling client |
139 using <code>intent.postResult</code>: | 139 using <code>intent.postResult</code>: |
140 </p> | 140 </p> |
141 | 141 |
142 <pre> | 142 <pre> |
143 chrome.experimental.app.onLaunched(function(intent) { | 143 chrome.app.runtime.onLaunched(function(intent) { |
144 // App Launched | 144 // App Launched |
145 console.log(intent.action); | 145 console.log(intent.action); |
146 console.log(intent.type); | 146 console.log(intent.type); |
147 var data = intent.data; | 147 var data = intent.data; |
148 // Do something with the data; | 148 // Do something with the data; |
149 | 149 |
150 intent.postResult(newData); | 150 intent.postResult(newData); |
151 }); | 151 }); |
152 </pre> | 152 </pre> |
153 | 153 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 var intent = new WebKitIntent("http://webintents.org/edit", "image/png", "dataUr
i://"); | 204 var intent = new WebKitIntent("http://webintents.org/edit", "image/png", "dataUr
i://"); |
205 | 205 |
206 var onSuccess = function(data) {}; | 206 var onSuccess = function(data) {}; |
207 var onError = function() {}; | 207 var onError = function() {}; |
208 | 208 |
209 window.navigator.webkitStartActivity(intent, onSuccess, onError); | 209 window.navigator.webkitStartActivity(intent, onSuccess, onError); |
210 </pre> | 210 </pre> |
211 | 211 |
212 <h3>Service</h3> | 212 <h3>Service</h3> |
213 <pre> | 213 <pre> |
214 chrome.experimental.app.onLaunched(function(intent) { | 214 chrome.app.runtime.onLaunched(function(intent) { |
215 // App Launched | 215 // App Launched |
216 console.log(intent.action); | 216 console.log(intent.action); |
217 console.log(intent.type); | 217 console.log(intent.type); |
218 var data = intent.data; | 218 var data = intent.data; |
219 // Do something with the data; | 219 // Do something with the data; |
220 | 220 |
221 intent.postResult(newData); | 221 intent.postResult(newData); |
222 }); | 222 }); |
223 </pre> | 223 </pre> |
224 | 224 |
225 <p class="backtotop"><a href="#top">Back to top</a></p> | 225 <p class="backtotop"><a href="#top">Back to top</a></p> |
OLD | NEW |