Search in sources :

Example 1 with LocalFilesystemURL

use of org.apache.cordova.file.LocalFilesystemURL in project jpHolo by teusink.

the class Capture method createMediaFile.

/**
     * Creates a JSONObject that represents a File from the Uri
     *
     * @param data the Uri of the audio/image/video
     * @return a JSONObject that represents a File
     * @throws IOException
     */
private JSONObject createMediaFile(Uri data) {
    File fp = webView.getResourceApi().mapUriToFile(data);
    JSONObject obj = new JSONObject();
    Class webViewClass = webView.getClass();
    PluginManager pm = null;
    try {
        Method gpm = webViewClass.getMethod("getPluginManager");
        pm = (PluginManager) gpm.invoke(webView);
    } catch (NoSuchMethodException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
    if (pm == null) {
        try {
            Field pmf = webViewClass.getField("pluginManager");
            pm = (PluginManager) pmf.get(webView);
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {
        }
    }
    FileUtils filePlugin = (FileUtils) pm.getPlugin("File");
    LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(fp.getAbsolutePath());
    try {
        // File properties
        obj.put("name", fp.getName());
        obj.put("fullPath", fp.toURI().toString());
        if (url != null) {
            obj.put("localURL", url.toString());
        }
        // is stored in the audio or video content store.
        if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
            if (data.toString().contains("/audio/")) {
                obj.put("type", AUDIO_3GPP);
            } else {
                obj.put("type", VIDEO_3GPP);
            }
        } else {
            obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
        }
        obj.put("lastModifiedDate", fp.lastModified());
        obj.put("size", fp.length());
    } catch (JSONException e) {
        // this will never happen
        e.printStackTrace();
    }
    return obj;
}
Also used : FileUtils(org.apache.cordova.file.FileUtils) JSONException(org.json.JSONException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PluginManager(org.apache.cordova.PluginManager) Field(java.lang.reflect.Field) JSONObject(org.json.JSONObject) File(java.io.File) LocalFilesystemURL(org.apache.cordova.file.LocalFilesystemURL)

Aggregations

File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 PluginManager (org.apache.cordova.PluginManager)1 FileUtils (org.apache.cordova.file.FileUtils)1 LocalFilesystemURL (org.apache.cordova.file.LocalFilesystemURL)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1