{"id":6449,"date":"2014-01-09T18:25:32","date_gmt":"2014-01-09T10:25:32","guid":{"rendered":"http:\/\/mynotes.org\/tech\/?p=6449"},"modified":"2014-04-28T10:41:10","modified_gmt":"2014-04-28T02:41:10","slug":"%e5%9c%a8phonegap%e7%92%b0%e5%a2%83%e4%b8%8b%ef%bc%8c%e6%aa%a2%e6%9f%a5%e6%aa%94%e6%a1%88%e6%98%af%e5%90%a6%e5%b7%b2%e7%b6%93%e5%ad%98%e5%9c%a8","status":"publish","type":"post","link":"https:\/\/mynotes.org\/tech\/2014\/01\/09\/6449.htm","title":{"rendered":"\u5728phonegap\u74b0\u5883\u4e0b\uff0c\u6aa2\u67e5\u6a94\u6848\u662f\u5426\u5df2\u7d93\u5b58\u5728"},"content":{"rendered":"<p>\u52a0\u83f2\u8c93\u61c9\u7528\u7a0b\u5f0fAPP\u7684\u529f\u80fd\u4e4b\u4e00\uff0c\u662f\u53ef\u4ee5\u4e0b\u8f09\u96e2\u7dda\u6a94\u6848\u3002\u4f46\u662f\u5728\u4e0b\u8f09\u4e4b\u524d\uff0c\u5e0c\u671b\u80fd\u6aa2\u67e5\u884c\u52d5\u88dd\u7f6e\u88e1\u9762\u662f\u5426\u5df2\u7d93\u6709\u4e0b\u8f09\u904e\u540c\u6a23\u6a94\u6848\uff0c\u4e26\u505a\u51fa\u4e0d\u540c\u7684\u986f\u793a\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u6aa2\u67e5\u6a94\u6848\u662f\u5426\u5b58\u5728\u7684\u8a9e\u6cd5\uff08\u53ef\u4ee5\u76f4\u63a5\u5beb\u5728HTML\u6a94\u88e1\u9762\uff09\uff1a<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\nfunction checkIfFileExists(path){\r\n    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){\r\n        fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);\r\n    }, getFSFail); \/\/of requestFileSystem\r\n}\r\nfunction fileExists(fileEntry){\r\n    alert(&quot;File &quot; + fileEntry.fullPath + &quot; exists!&quot;);\r\n}\r\nfunction fileDoesNotExist(){\r\n    alert(&quot;file does not exist&quot;);\r\n}\r\nfunction getFSFail(evt) {\r\n    console.log(evt.target.error.code);\r\n}\r\n&lt;\/script&gt;\r\n&lt;input type=&quot;button&quot; value=&quot;Check&quot; onClick=&quot;checkIfFileExists('path\/to\/your\/file.txt');&quot;\/&gt;\r\n<\/pre>\n<p>\u53c3\u8003\u4f86\u6e90\uff1a<a href=\"http:\/\/stackoverflow.com\/questions\/10294166\/how-to-check-a-files-existence-in-phone-directory-with-phonegap\">http:\/\/stackoverflow.com\/questions\/10294166\/how-to-check-a-files-existence-in-phone-directory-with-phonegap<\/a><\/p>\n<p>\u8981\u5728\u9801\u9762\u8f09\u5165\u6642\u5c31\u505a\u6aa2\u67e5\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndocument.addEventListener(&quot;deviceready&quot;, onDeviceReady, false);\r\n\r\nfunction onDeviceReady() {\r\n    \/\/ Now safe to use the Cordova API\r\n}\r\n<\/pre>\n<p>\u53c3\u8003\u4f86\u6e90\uff1a<a href=\"http:\/\/docs.phonegap.com\/en\/2.3.0\/cordova_events_events.md.html#deviceready\">http:\/\/docs.phonegap.com\/en\/2.3.0\/cordova_events_events.md.html#deviceready<\/a><\/p>\n<p>\u6aa2\u67e5\u5b8c\u6210\u4e4b\u5f8c\u8f38\u51fa\u5c0d\u61c9\u7d50\u679c\u7684\u5b57\u4e32\uff08\u52a0\u5165\u6aa2\u67e5\u7d50\u679c\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff09\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndocument.getElementById('message_text').innerHTML=&quot;this is your message&quot;;\r\n<\/pre>\n<p>\u8a18\u5f97\u5728\u4e0b\u65b9\u52a0\u5165\u4e00\u500b\u5c0d\u61c9\u7684div\u6a19\u7c64\u986f\u793a\u6b64\u8a0a\u606f<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div id=&quot;message_text&quot;&gt;&lt;\/div&gt;\r\n<\/pre>\n<p>\u6700\u5f8c\u5b8c\u6574\u7684\u7a0b\u5f0f\u5167\u5bb9\uff1a<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n &lt;script type=&quot;text\/javascript&quot; src=&quot;cordova-2.3.0.js&quot;&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n \t\t&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\t\t\tdocument.addEventListener(&quot;deviceReady&quot;, onDeviceReady, false);\r\n\t\t\tfunction onDeviceReady() {\r\n    \t\t\t\/\/ Now safe to use the PhoneGap API\r\n\t\t\t    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){\r\n\t\t\t        fileSystem.root.getFile('path\/to\/your\/file.txt', { create: false }, fileExists, fileDoesNotExist);\r\n\t\t\t    }, getFSFail); \/\/of requestFileSystem\r\n\r\n\t\t\tfunction fileExists(fileEntry){\r\n\t\t\tdocument.getElementById('message_text').innerHTML=&quot;File exists&quot;;\r\n\t\t\t}\r\n\t\t\tfunction fileDoesNotExist(){\r\n\t\t\tdocument.getElementById('message_text').innerHTML=&quot;File doesn't exist&quot;;\r\n\t\t\t}\r\n\t\t\tfunction getFSFail(evt) {\r\n\t\t\tdocument.getElementById('message_text').innerHTML=&quot;System error&quot;;\r\n\t\t\t} \r\n\t\t\t}\r\n\t\t&lt;\/script&gt;\r\n\t\r\n&lt;div id=&quot;message_text&quot;&gt;&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u52a0\u83f2\u8c93\u61c9\u7528\u7a0b\u5f0fAPP\u7684\u529f\u80fd\u4e4b\u4e00\uff0c\u662f\u53ef\u4ee5\u4e0b\u8f09\u96e2\u7dda\u6a94\u6848\u3002\u4f46\u662f\u5728\u4e0b\u8f09\u4e4b\u524d\uff0c\u5e0c\u671b\u80fd\u6aa2\u67e5\u884c\u52d5\u88dd\u7f6e\u88e1\u9762\u662f\u5426\u5df2\u7d93\u6709\u4e0b\u8f09\u904e\u540c\u6a23 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[126,131],"tags":[103,88,35,40,100],"class_list":["post-6449","post","type-post","status-publish","format-standard","hentry","category-android","category-app-android","tag-android0","tag-app","tag-html","tag-java-scripts","tag-phonegap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/posts\/6449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/comments?post=6449"}],"version-history":[{"count":2,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/posts\/6449\/revisions"}],"predecessor-version":[{"id":6451,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/posts\/6449\/revisions\/6451"}],"wp:attachment":[{"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/media?parent=6449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/categories?post=6449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mynotes.org\/tech\/wp-json\/wp\/v2\/tags?post=6449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}