Example usage for org.apache.cordova CordovaInterface startActivityForResult

List of usage examples for org.apache.cordova CordovaInterface startActivityForResult

Introduction

In this page you can find the example usage for org.apache.cordova CordovaInterface startActivityForResult.

Prototype

abstract public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode);

Source Link

Document

Launch an activity for which you would like a result when it finished.

Usage

From source file:com.samsung.spen.SpenTrayBar.java

License:Apache License

/**
 * call gallery for input image/*from  w  w w.  jav  a 2 s  .  co  m*/
 * 
 * @params nRequestCode
 *                  int
 */
private void callGalleryForInputImage(int nRequestCode) {
    if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) {
        Log.d(TAG, "Inside callGalleryForInputImage, request code is :" + nRequestCode);
    }
    CordovaInterface cordova = mContextParams.getSpenCustomDrawPlugin().cordova;

    try {
        Intent galleryIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        mSpenCustomDrawPlugin.setIdAndSurfaceType(mOptions.getId(), mOptions.getSurfaceType());
        cordova.startActivityForResult((CordovaPlugin) mSpenCustomDrawPlugin, galleryIntent, nRequestCode);
    } catch (ActivityNotFoundException e) {
        Log.d(TAG, "unable to set the background: " + e.getMessage());
        e.printStackTrace();
        SpenException.sendPluginResult(SpenExceptionType.FAILED_SET_BACKGROUND_IMAGE,
                mContextParams.getCallbackContext());
    }
}

From source file:me.donaldepignosis.cordova.plugins.streamingmedia.mod.StreamingMedia.java

License:Open Source License

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);//from ww  w.j  av  a  2  s.  co m
            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;
}