
$('#makeVideo').click(function() { navigator.device.capture.captureVideo(captureSuccess, captureError, { limit : 1 } ); function captureSuccess(mediaFiles) { console.log("Capturing video successfully finished"); } function captureError(error) { console.log("Video capture error + " + error.code); } }); public class IntentPlugin extends Plugin { … } private void openPhotoCamera() throws IOException { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); this.cordova.getActivity().startActivity(intent); } private void openBrowse(String url) throws IOException { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); this.cordova.getActivity().startActivity(intent); } private void openMap(String url) throws IOException { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url)); this.cordova.getActivity().startActivity(intent); } @Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("makePhoto")) { openPhotoCamera(); } else if (action.equals("lookAtBrowse")) { openBrowse(args.getString(0)); } else if (action.equals("lookAtMap")) { openMap(args.getString(0)); } 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); } } <plugin name="IntentPlugin" value="com.ruswizards.phonegapplugin.IntentPlugin"/> function IntentPlugin() { }; if(!window.plugins) { window.plugins = {}; } if (!window.plugins.intentPlugin) { window.plugins.intentPlugin = new IntentPlugin(); } IntentPlugin.prototype.makePhotoFunction = function(url) { cordova.exec(null, null, "IntentPlugin", "makePhoto", [url]); }; IntentPlugin.prototype.lookAtBrowseFunction = function(url) { cordova.exec(null, null, "IntentPlugin", "lookAtBrowse", [url]); }; IntentPlugin.prototype.lookAtMapFunction = function(url) { cordova.exec(null, null, "IntentPlugin", "lookAtMap", [url]); }; <script type="text/javascript" charset="utf-8" src="intentPlagin.js"></script> <a id="makeVideo" data-role="button">Create video</a> <a id="makePhoto" data-role="button">Create photo</a> <a id="lookAtBrowse" data-role="button">Open browse</a> <a id="lookAtMap" data-role="button">Open map</a> $('#makePhoto').click(function() { window.plugins.intentPlugin.makePhotoFunction(""); }); $('#lookAtBrowse').click(function() { window.plugins.intentPlugin.lookAtBrowseFunction("http://www.google.com"); }); $('#lookAtMap').click(function() { window.plugins.intentPlugin.lookAtMapFunction("geo:52.431198,31.004899"); }); Source: https://habr.com/ru/post/150689/
All Articles