List of usage examples for org.apache.cordova.file LocalFilesystemURL toString
public String toString()
From source file:br.com.denguezerocidadao.Capture.java
License:Apache License
/** * 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/*from w w w .j av a2 s .c o m*/ */ 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()); } // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it // 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; }
From source file:com.oe.phonegap.plugins.AutoRecordVideo.java
License:Apache License
/** * 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//from www . ja v a 2 s. c om */ 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()); } // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it // 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; }