org.apache.cordova.CordovaPlugin Java Examples

The following examples show how to use org.apache.cordova.CordovaPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemWebChromeClient.java    From app-icon with MIT License 6 votes vote down vote up
@Override
/**
 * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
 *
 * This also checks for the Geolocation Plugin and requests permission from the application  to use Geolocation.
 *
 * @param origin
 * @param callback
 */
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
    super.onGeolocationPermissionsShowPrompt(origin, callback);
    callback.invoke(origin, true, false);
    //Get the plugin, it should be loaded
    CordovaPlugin geolocation = parentEngine.pluginManager.getPlugin("Geolocation");
    if(geolocation != null && !geolocation.hasPermisssion())
    {
        geolocation.requestPermissions(0);
    }

}
 
Example #2
Source File: PermissionHelper.java    From cordova-background-geolocation-services with Apache License 2.0 6 votes vote down vote up
/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod(
                "requestPermissions", CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException);
    }
}
 
Example #3
Source File: PluginManager.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * Send a message to all plugins.
 *
 * @param id                The message id
 * @param data              The message data
 * @return                  Object to stop propagation or null
 */
public Object postMessage(String id, Object data) {
    Object obj = this.ctx.onMessage(id, data);
    if (obj != null) {
        return obj;
    }

    for (CordovaPlugin plugin : this.pluginMap.values()) {
        if (plugin != null) {
            obj = plugin.onMessage(id, data);
            if (obj != null) {
                return obj;
            }
        }
    }
    return null;
}
 
Example #4
Source File: PermissionHelper.java    From reacteu-app with MIT License 6 votes vote down vote up
private static void deliverPermissionResult(CordovaPlugin plugin, int requestCode, String[] permissions) {
    // Generate the request results
    int[] requestResults = new int[permissions.length];
    Arrays.fill(requestResults, PackageManager.PERMISSION_GRANTED);

    try {
        Method onRequestPermissionResult = CordovaPlugin.class.getDeclaredMethod(
                "onRequestPermissionResult", int.class, String[].class, int[].class);

        onRequestPermissionResult.invoke(plugin, requestCode, permissions, requestResults);
    } catch (NoSuchMethodException noSuchMethodException) {
        // Should never be caught since the plugin must be written for cordova-android 5.0.0+ if it
        // made it to this point
        LOG.e(LOG_TAG, "NoSuchMethodException when delivering permissions results", noSuchMethodException);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when delivering permissions results", illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method may throw a JSONException. We are just duplicating cordova-android's
        // exception handling behavior here; all it does is log the exception in CordovaActivity,
        // print the stacktrace, and ignore it
        LOG.e(LOG_TAG, "InvocationTargetException when delivering permissions results", invocationTargetException);
    }
}
 
Example #5
Source File: PluginManager.java    From reader with MIT License 6 votes vote down vote up
/**
 * Called when the URL of the webview changes.
 *
 * @param url               The URL that is being changed to.
 * @return                  Return false to allow the URL to load, return true to prevent the URL from loading.
 */
public boolean onOverrideUrlLoading(String url) {
    // Deprecated way to intercept URLs. (process <url-filter> tags).
    // Instead, plugins should not include <url-filter> and instead ensure
    // that they are loaded before this function is called (either by setting
    // the onload <param> or by making an exec() call to them)
    for (PluginEntry entry : this.entryMap.values()) {
        List<String> urlFilters = urlMap.get(entry.service);
        if (urlFilters != null) {
            for (String s : urlFilters) {
                if (url.startsWith(s)) {
                    return getPlugin(entry.service).onOverrideUrlLoading(url);
                }
            }
        } else {
            CordovaPlugin plugin = pluginMap.get(entry.service);
            if (plugin != null && plugin.onOverrideUrlLoading(url)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: SystemWebChromeClient.java    From keemob with MIT License 6 votes vote down vote up
@Override
/**
 * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
 *
 * This also checks for the Geolocation Plugin and requests permission from the application  to use Geolocation.
 *
 * @param origin
 * @param callback
 */
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
    super.onGeolocationPermissionsShowPrompt(origin, callback);
    callback.invoke(origin, true, false);
    //Get the plugin, it should be loaded
    CordovaPlugin geolocation = parentEngine.pluginManager.getPlugin("Geolocation");
    if(geolocation != null && !geolocation.hasPermisssion())
    {
        geolocation.requestPermissions(0);
    }

}
 
Example #7
Source File: CameraLauncher.java    From reader with MIT License 6 votes vote down vote up
/**
     * Take a picture with the camera.
     * When an image is captured or the camera view is cancelled, the result is returned
     * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
     *
     * The image can either be returned as a base64 string or a URI that points to the file.
     * To display base64 string in an img tag, set the source to:
     *      img.src="data:image/jpeg;base64,"+result;
     * or to display URI in an img tag
     *      img.src=result;
     *
     * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
     * @param returnType        Set the type of image to return.
     */
    public void takePicture(int returnType, int encodingType) {
        // Save the number of images currently on disk for later
        this.numPics = queryImgDB(whichContentStore()).getCount();

        // Display camera
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        // Specify file so that large image is captured and returned
        File photo = createCaptureFile(encodingType);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
        this.imageUri = Uri.fromFile(photo);

        if (this.cordova != null) {
            this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
        }
//        else
//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
    }
 
Example #8
Source File: CameraLauncher.java    From reader with MIT License 6 votes vote down vote up
/**
     * Take a picture with the camera.
     * When an image is captured or the camera view is cancelled, the result is returned
     * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
     *
     * The image can either be returned as a base64 string or a URI that points to the file.
     * To display base64 string in an img tag, set the source to:
     *      img.src="data:image/jpeg;base64,"+result;
     * or to display URI in an img tag
     *      img.src=result;
     *
     * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
     * @param returnType        Set the type of image to return.
     */
    public void takePicture(int returnType, int encodingType) {
        // Save the number of images currently on disk for later
        this.numPics = queryImgDB(whichContentStore()).getCount();

        // Display camera
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        // Specify file so that large image is captured and returned
        File photo = createCaptureFile(encodingType);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
        this.imageUri = Uri.fromFile(photo);

        if (this.cordova != null) {
            this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
        }
//        else
//            LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
    }
 
Example #9
Source File: CordovaResourceApiTest.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    activity = this.getActivity();
    cordovaWebView = activity.cordovaWebView;
    resourceApi = cordovaWebView.getResourceApi();
    resourceApi.setThreadCheckingEnabled(false);
    cordovaWebView.pluginManager.addService(new PluginEntry("CordovaResourceApiTestPlugin1", new CordovaPlugin() {
        @Override
        public Uri remapUri(Uri uri) {
            if (uri.getQuery() != null && uri.getQuery().contains("pluginRewrite")) {
                return cordovaWebView.getResourceApi().remapUri(
                        Uri.parse("data:text/plain;charset=utf-8,pass"));
            }
            return null;
        }
        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
            synchronized (CordovaResourceApiTest.this) {
                execPayload = args.getString(0);
                execStatus = args.getInt(1);
                CordovaResourceApiTest.this.notify();
            }
            return true;
        }
    }));
}
 
Example #10
Source File: PluginManager.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * Get the plugin object that implements the service.
 * If the plugin object does not already exist, then create it.
 * If the service doesn't exist, then return null.
 *
 * @param service       The name of the service.
 * @return              CordovaPlugin or null
 */
public CordovaPlugin getPlugin(String service) {
    CordovaPlugin ret = pluginMap.get(service);
    if (ret == null) {
        PluginEntry pe = entryMap.get(service);
        if (pe == null) {
            return null;
        }
        if (pe.plugin != null) {
            ret = pe.plugin;
        } else {
            ret = instantiatePlugin(pe.pluginClass);
        }
        ret.privateInitialize(ctx, app, app.getPreferences());
        pluginMap.put(service, ret);
    }
    return ret;
}
 
Example #11
Source File: X5WebChromeClient.java    From cordova-plugin-x5engine-webview with Apache License 2.0 6 votes vote down vote up
@Override
/**
 * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
 *
 * This also checks for the Geolocation Plugin and requests permission from the application  to use Geolocation.
 *
 * @param origin
 * @param callback
 */
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissionsCallback callback) {
    super.onGeolocationPermissionsShowPrompt(origin, callback);
    callback.invoke(origin, true, false);
    //Get the plugin, it should be loaded
    CordovaPlugin geolocation = parentEngine.pluginManager.getPlugin("Geolocation");
    if(geolocation != null && !geolocation.hasPermisssion())
    {
        geolocation.requestPermissions(0);
    }

}
 
Example #12
Source File: SystemWebChromeClient.java    From keemob with MIT License 6 votes vote down vote up
@Override
/**
 * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
 *
 * This also checks for the Geolocation Plugin and requests permission from the application  to use Geolocation.
 *
 * @param origin
 * @param callback
 */
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
    super.onGeolocationPermissionsShowPrompt(origin, callback);
    callback.invoke(origin, true, false);
    //Get the plugin, it should be loaded
    CordovaPlugin geolocation = parentEngine.pluginManager.getPlugin("Geolocation");
    if(geolocation != null && !geolocation.hasPermisssion())
    {
        geolocation.requestPermissions(0);
    }

}
 
Example #13
Source File: PluginManager.java    From bluemix-parking-meter with MIT License 6 votes vote down vote up
/**
 * Get the plugin object that implements the service.
 * If the plugin object does not already exist, then create it.
 * If the service doesn't exist, then return null.
 *
 * @param service       The name of the service.
 * @return              CordovaPlugin or null
 */
public CordovaPlugin getPlugin(String service) {
    CordovaPlugin ret = pluginMap.get(service);
    if (ret == null) {
        PluginEntry pe = entryMap.get(service);
        if (pe == null) {
            return null;
        }
        if (pe.plugin != null) {
            ret = pe.plugin;
        } else {
            ret = instantiatePlugin(pe.pluginClass);
        }
        ret.privateInitialize(ctx, app, app.getPreferences());
        pluginMap.put(service, ret);
    }
    return ret;
}
 
Example #14
Source File: PluginManager.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * Called when the URL of the webview changes.
 *
 * @param url               The URL that is being changed to.
 * @return                  Return false to allow the URL to load, return true to prevent the URL from loading.
 */
public boolean onOverrideUrlLoading(String url) {
    // Deprecated way to intercept URLs. (process <url-filter> tags).
    // Instead, plugins should not include <url-filter> and instead ensure
    // that they are loaded before this function is called (either by setting
    // the onload <param> or by making an exec() call to them)
    for (PluginEntry entry : this.entryMap.values()) {
        List<String> urlFilters = urlMap.get(entry.service);
        if (urlFilters != null) {
            for (String s : urlFilters) {
                if (url.startsWith(s)) {
                    return getPlugin(entry.service).onOverrideUrlLoading(url);
                }
            }
        } else {
            CordovaPlugin plugin = pluginMap.get(entry.service);
            if (plugin != null && plugin.onOverrideUrlLoading(url)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #15
Source File: CordovaActivity.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
@Override
    /**
     * Called when an activity you launched exits, giving you the requestCode you started it with,
     * the resultCode it returned, and any additional data from it.
     *
     * @param requestCode       The request code originally supplied to startActivityForResult(),
     *                          allowing you to identify who this result came from.
     * @param resultCode        The integer result code returned by the child activity through its setResult().
     * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
     */
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        LOG.d(TAG, "Incoming Result");
        super.onActivityResult(requestCode, resultCode, intent);
        Log.d(TAG, "Request code = " + requestCode);
        if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
        	ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
            Log.d(TAG, "did we get here?");
            if (null == mUploadMessage)
                return;
            Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
            Log.d(TAG, "result = " + result);
//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
//            Log.d(TAG, "result = " + filepath);
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
        }
        CordovaPlugin callback = this.activityResultCallback;
        if(callback == null && initCallbackClass != null) {
            // The application was restarted, but had defined an initial callback
            // before being shut down.
            this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
            callback = this.activityResultCallback;
        }
        if(callback != null) {
            LOG.d(TAG, "We have a callback to send this result to");
            callback.onActivityResult(requestCode, resultCode, intent);
        }
    }
 
Example #16
Source File: CameraLauncher.java    From reader with MIT License 5 votes vote down vote up
/**
 * Brings up the UI to perform crop on passed image URI
 * 
 * @param picUri
 */
private void performCrop(Uri picUri) {
  try {
    Intent cropIntent = new Intent("com.android.camera.action.CROP");
    // indicate image type and Uri
    cropIntent.setDataAndType(picUri, "image/*");
    // set crop properties
    cropIntent.putExtra("crop", "true");
    // indicate output X and Y
    if (targetWidth > 0) {
        cropIntent.putExtra("outputX", targetWidth);
    }
    if (targetHeight > 0) {
        cropIntent.putExtra("outputY", targetHeight);
    }
    if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
    }
    // create new file handle to get full resolution crop
    croppedUri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
    cropIntent.putExtra("output", croppedUri);

    // start the activity - we handle returning in onActivityResult

    if (this.cordova != null) {
      this.cordova.startActivityForResult((CordovaPlugin) this,
          cropIntent, CROP_CAMERA);
    }
  } catch (ActivityNotFoundException anfe) {
    Log.e(LOG_TAG, "Crop operation not supported on this device");
    // Send Uri back to JavaScript for viewing image
    this.callbackContext.success(picUri.toString());
  }
}
 
Example #17
Source File: CordovaActivity.java    From reader with MIT License 5 votes vote down vote up
/**
 * Launch an activity for which you would like a result when it finished. When this activity exits,
 * your onActivityResult() method will be called.
 *
 * @param command           The command object
 * @param intent            The intent to start
 * @param requestCode       The request code that is passed to callback to identify the activity
 */
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
    this.activityResultCallback = command;
    this.activityResultKeepRunning = this.keepRunning;

    // If multitasking turned on, then disable it for activities that return results
    if (command != null) {
        this.keepRunning = false;
    }

    // Start activity
    super.startActivityForResult(intent, requestCode);
}
 
Example #18
Source File: PluginManager.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Get the plugin object that implements the service.
 * If the plugin object does not already exist, then create it.
 * If the service doesn't exist, then return null.
 *
 * @param service       The name of the service.
 * @return              CordovaPlugin or null
 */
public CordovaPlugin getPlugin(String service) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #19
Source File: PluginManager.java    From wildfly-samples with MIT License 5 votes vote down vote up
/**
 * Get the plugin object that implements the service.
 * If the plugin object does not already exist, then create it.
 * If the service doesn't exist, then return null.
 *
 * @param service       The name of the service.
 * @return              CordovaPlugin or null
 */
public CordovaPlugin getPlugin(String service) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #20
Source File: PluginEntry.java    From L.TileLayer.Cordova with MIT License 5 votes vote down vote up
private PluginEntry(String service, String pluginClass, boolean onload, CordovaPlugin plugin, List<String> urlFilters) {
    this.service = service;
    this.pluginClass = pluginClass;
    this.onload = onload;
    this.urlFilters = urlFilters;
    this.plugin = plugin;
}
 
Example #21
Source File: PluginManager.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
Uri remapUri(Uri uri) {
    for (CordovaPlugin plugin : this.pluginMap.values()) {
        Uri ret = plugin.remapUri(uri);
        if (ret != null) {
            return ret;
        }
    }
    return null;
}
 
Example #22
Source File: PluginEntry.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
private PluginEntry(String service, String pluginClass, boolean onload, CordovaPlugin plugin, List<String> urlFilters) {
    this.service = service;
    this.pluginClass = pluginClass;
    this.onload = onload;
    this.urlFilters = urlFilters;
    this.plugin = plugin;
}
 
Example #23
Source File: StreamingMedia.java    From cordova-plugin-streaming-media with MIT License 5 votes vote down vote up
private boolean play(final Class activityClass, final String url, final JSONObject options) {
	final CordovaInterface cordovaObj = cordova;
	final CordovaPlugin plugin = this;

	cordova.getActivity().runOnUiThread(new Runnable() {
		public void run() {
			final Intent streamIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), activityClass);
			Bundle extras = new Bundle();
			extras.putString("mediaUrl", url);

			if (options != null) {
				Iterator<String> optKeys = options.keys();
				while (optKeys.hasNext()) {
					try {
						final String optKey = (String)optKeys.next();
						if (options.get(optKey).getClass().equals(String.class)) {
							extras.putString(optKey, (String)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						} else if (options.get(optKey).getClass().equals(Boolean.class)) {
							extras.putBoolean(optKey, (Boolean)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						}

					} catch (JSONException e) {
						Log.e(TAG, "JSONException while trying to read options. Skipping option.");
					}
				}
				streamIntent.putExtras(extras);
			}

			cordovaObj.startActivityForResult(plugin, streamIntent, ACTIVITY_CODE_PLAY_MEDIA);
		}
	});
	return true;
}
 
Example #24
Source File: PluginEntry.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Returns whether the given class extends CordovaPlugin.
 */
@SuppressWarnings("rawtypes")
private boolean isCordovaPlugin(Class c) {
    if (c != null) {
        return org.apache.cordova.CordovaPlugin.class.isAssignableFrom(c);
    }
    return false;
}
 
Example #25
Source File: ContactManager.java    From jpHolo with MIT License 5 votes vote down vote up
/**
 * Launches the Contact Picker to select a single contact.
 */
private void pickContactAsync() {
    final CordovaPlugin plugin = (CordovaPlugin) this;
    Runnable worker = new Runnable() {
        public void run() {
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
            plugin.cordova.startActivityForResult(plugin, contactPickerIntent, CONTACT_PICKER_RESULT);
        }
    };
    this.cordova.getThreadPool().execute(worker);
}
 
Example #26
Source File: CordovaActivity.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/**
 * Launch an activity for which you would like a result when it finished. When this activity exits,
 * your onActivityResult() method will be called.
 *
 * @param command           The command object
 * @param intent            The intent to start
 * @param requestCode       The request code that is passed to callback to identify the activity
 */
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
    this.activityResultCallback = command;
    this.activityResultKeepRunning = this.keepRunning;

    // If multitasking turned on, then disable it for activities that return results
    if (command != null) {
        this.keepRunning = false;
    }

    // Start activity
    super.startActivityForResult(intent, requestCode);
}
 
Example #27
Source File: CordovaActivity.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Launch an activity for which you would like a result when it finished. When this activity exits,
 * your onActivityResult() method will be called.
 *
 * @param command           The command object
 * @param intent            The intent to start
 * @param requestCode       The request code that is passed to callback to identify the activity
 */
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) {
    this.activityResultCallback = command;
    this.activityResultKeepRunning = this.keepRunning;

    // If multitasking turned on, then disable it for activities that return results
    if (command != null) {
        this.keepRunning = false;
    }

    // Start activity
    super.startActivityForResult(intent, requestCode);
}
 
Example #28
Source File: Vitamio.java    From Vitamio-Cordova-Plugin with MIT License 5 votes vote down vote up
private boolean play(final Class activityClass, final String url, final JSONObject options) {
	final CordovaInterface cordovaObj = cordova;
	final CordovaPlugin plugin = this;

	cordova.getActivity().runOnUiThread(new Runnable() {
		public void run() {
			final Intent streamIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), activityClass);
			Bundle extras = new Bundle();
			extras.putString("mediaUrl", url);

			if (options != null) {
				Iterator<String> optKeys = options.keys();
				while (optKeys.hasNext()) {
					try {
						final String optKey = (String)optKeys.next();
						if (options.get(optKey).getClass().equals(String.class)) {
							extras.putString(optKey, (String)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						} else if (options.get(optKey).getClass().equals(Boolean.class)) {
							extras.putBoolean(optKey, (Boolean)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						}

					} catch (JSONException e) {
						Log.e(TAG, "JSONException while trying to read options. Skipping option.");
					}
				}
				streamIntent.putExtras(extras);
			}

			cordovaObj.startActivityForResult(plugin, streamIntent, ACTIVITY_CODE_PLAY_MEDIA);
		}
	});
	return true;
}
 
Example #29
Source File: PluginManager.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * Get the plugin object that implements the service.
 * If the plugin object does not already exist, then create it.
 * If the service doesn't exist, then return null.
 *
 * @param service       The name of the service.
 * @return              CordovaPlugin or null
 */
public CordovaPlugin getPlugin(String service) {
    PluginEntry entry = this.entries.get(service);
    if (entry == null) {
        return null;
    }
    CordovaPlugin plugin = entry.plugin;
    if (plugin == null) {
        plugin = entry.createPlugin(this.app, this.ctx);
    }
    return plugin;
}
 
Example #30
Source File: PluginManager.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the activity receives a new intent.
 */
public void onNewIntent(Intent intent) {
    for (CordovaPlugin plugin : this.pluginMap.values()) {
        if (plugin != null) {
            plugin.onNewIntent(intent);
        }
    }
}