diff --git a/AndroidManifest.xml b/AndroidManifest.xml index da6d3907..2d214c8f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,17 +2,16 @@ - - - - + + + @@ -29,6 +28,6 @@ - + \ No newline at end of file diff --git a/assets/www/index.html b/assets/www/index.html index cf787db1..b77930ab 100644 --- a/assets/www/index.html +++ b/assets/www/index.html @@ -93,6 +93,11 @@ navigator.file.read('/sdcard/phonegap.txt', fail , fail); } + function writeFile() + { + navigator.file.write('foo.txt', "This is a test of writing to a file", fail, fail); + } + function init(){ document.addEventListener("touchmove", preventBehavior, false); setTimeout(deviceInfo, 1); @@ -120,6 +125,7 @@ Vibrate Get a Picture Read from file + Write to File
diff --git a/default.properties b/default.properties index 8433081e..62bef18a 100644 --- a/default.properties +++ b/default.properties @@ -7,16 +7,8 @@ # "build.properties", and override values to adapt the script to your # project structure. -# apk configurations. This property allows creation of APK files with limited -# resources. For example, if your application contains many locales and -# you wish to release multiple smaller apks instead of a large one, you can -# define configuration to create apks with limited language sets. -# Format is a comma separated list of configuration names. For each -# configuration, a property will declare the resource configurations to -# include. Example: -# apk-configurations=european,northamerica -# apk-config-european=en,fr,it,de,es -# apk-config-northamerica=en,es apk-configurations= # Project target. -target=Google Inc.:Google APIs:4 +target=android-4 +# Indicates whether an apk should be generated for each density. +split.density=false diff --git a/src/com/phonegap/demo/DroidGap.java b/src/com/phonegap/demo/DroidGap.java index 8ed6e568..8abdc669 100644 --- a/src/com/phonegap/demo/DroidGap.java +++ b/src/com/phonegap/demo/DroidGap.java @@ -98,7 +98,7 @@ public class DroidGap extends Activity { geo = new GeoBroker(appView, this); accel = new AccelListener(this, appView); launcher = new CameraLauncher(appView, this); - fs = new FileUtils(); + fs = new FileUtils(appView); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(gap, "DroidGap"); diff --git a/src/com/phonegap/demo/FileUtils.java b/src/com/phonegap/demo/FileUtils.java index b78c76a2..90a01a5d 100644 --- a/src/com/phonegap/demo/FileUtils.java +++ b/src/com/phonegap/demo/FileUtils.java @@ -2,12 +2,21 @@ package com.phonegap.demo; import java.io.*; +import android.webkit.WebView; + public class FileUtils { + + WebView mView; DirectoryManager fileManager; FileReader f_in; FileWriter f_out; + FileUtils(WebView view) + { + mView = view; + } + public int testSaveLocationExists(){ if (fileManager.testSaveLocationExists()) return 0; @@ -87,20 +96,20 @@ public class FileUtils { } catch (IOException e) { data = "FAIL: IO ERROR"; } - + + mView.loadUrl("javascript:navigator.file.hasRead('" + data + "')"); return data; } public int write(String filename, String data) { - { int i=0; String FilePath="/sdcard/" + filename; try { ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes()); byte buff[] = new byte[1024]; FileOutputStream out= - new FileOutputStream(FilePath); + new FileOutputStream(FilePath, true); do { int numread = in.read(buff); if (numread <= 0) @@ -110,9 +119,11 @@ public class FileUtils { i++; } while (true); out.flush(); - out.close(); - } catch (Exception e) { e.printStackTrace(); } - } + out.close(); + mView.loadUrl("javascript:navigator.file.winCallback('File written')"); + } catch (Exception e) { + mView.loadUrl("javascript:navigator.file.failCallback('Fail')"); + } return 0; } }