diff --git a/README.md b/README.md
index 471c812..b30a30e 100644
--- a/README.md
+++ b/README.md
@@ -7,16 +7,16 @@ Adding the Plugin to your project
-----------
Using this plugin requires Android PhoneGap. It has been successfully tested on Android device with Cordova 2.2
-To install the plugin, move ``````fileopener.js`````` to your project's www folder and include a reference to it in your html file after ``````cordova-2.2.0.js``````.
+To install the plugin, move ``````fileopener.js`````` to your project's www folder and include a reference to it in your html file after ``````cordova-2.7.0.js``````.
```````html
-
+
```````
Create a directory within your project called ``````src/com/phonegap/plugins/fileopener`````` and move ``````FileOpener.java`````` into it.
-In your ``````res/xml/plugins.xml`````` file add the following line:
+In your ``````res/xml/config.xml`````` file add the following line:
``````java
@@ -40,6 +40,9 @@ After you run the command above, Android device will either open the file with p
RELEASE NOTES
-------------
+May 21, 2013
+Update for Cordova-2.7.0
+
January 2, 2013
Initial release
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..cba6f2e
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,21 @@
+
+
+
+ FileOpener
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/FileOpener.java b/src/android/FileOpener.java
similarity index 77%
rename from FileOpener.java
rename to src/android/FileOpener.java
index 658bbde..5aaa2eb 100644
--- a/FileOpener.java
+++ b/src/android/FileOpener.java
@@ -8,52 +8,48 @@
package com.phonegap.plugins.fileopener;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
+import java.net.URLConnection;
+import org.apache.cordova.api.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
-import android.content.Context;
import android.content.Intent;
import android.net.Uri;
-import org.apache.cordova.api.Plugin;
-import org.apache.cordova.api.PluginResult;
+import org.apache.cordova.api.CordovaPlugin;
-public class FileOpener extends Plugin {
+public class FileOpener extends CordovaPlugin {
@Override
- public PluginResult execute(String action, JSONArray args, String callbackId) {
- PluginResult.Status status = PluginResult.Status.OK;
- String result = "";
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try {
if (action.equals("openFile")) {
openFile(args.getString(0));
+ callbackContext.success();
+ return true;
}
- else {
- status = PluginResult.Status.INVALID_ACTION;
- }
- return new PluginResult(status, result);
- } catch (JSONException e) {
- return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
} catch (IOException e) {
- return new PluginResult(PluginResult.Status.IO_EXCEPTION);
+ e.printStackTrace();
+ callbackContext.error(e.getMessage());
+ } catch (RuntimeException e) { // KLUDGE for Activity Not Found
+ e.printStackTrace();
+ callbackContext.error(e.getMessage());
}
+ return false;
}
private void openFile(String url) throws IOException {
// Create URI
Uri uri = Uri.parse(url);
- Intent intent = null;
+ Intent intent;
// Check what kind of file you are trying to open, by comparing the url with extensions.
// When the if condition is matched, plugin sets the correct intent (mime) type,
// so Android knew what application to use to open the file
-
+
if (url.contains(".doc") || url.contains(".docx")) {
// Word document
intent = new Intent(Intent.ACTION_VIEW);
@@ -94,7 +90,7 @@ private void openFile(String url) throws IOException {
// Video files
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
- }
+ }
//if you want you can also define the intent type for any other file
@@ -102,12 +98,18 @@ private void openFile(String url) throws IOException {
//in this case, Android will show all applications installed on the device
//so you can choose which application to use
+ // else {
+ // intent = new Intent(Intent.ACTION_VIEW);
+ // intent.setDataAndType(uri, "*/*");
+ // }
+
else {
+ String mimeType = URLConnection.guessContentTypeFromName(url);
intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(uri, "*/*");
+ intent.setDataAndType(uri, mimeType);
}
- this.cordova.getActivity().startActivity(intent);
+ this.cordova.getActivity().startActivity(intent); // TODO handle ActivityNotFoundException
}
}
diff --git a/fileopener.js b/www/fileopener.js
similarity index 71%
rename from fileopener.js
rename to www/fileopener.js
index ba99e4c..6f9b55b 100644
--- a/fileopener.js
+++ b/www/fileopener.js
@@ -13,7 +13,13 @@ function FileOpener() {
};
FileOpener.prototype.open = function(url) {
- cordova.exec(null, null, "FileOpener", "openFile", [url]);
+ var success = function() {
+ console.log("success!");
+ }
+ var failure = function(error) {
+ console.log(error);
+ }
+ cordova.exec(success, failure, "FileOpener", "openFile", [url]);
};
/**