Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

In this page you can find the example usage for android.content Intent getParcelableExtra.

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.entertailion.android.dial.MainActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == CODE_SWITCH_SERVER) {
        if (resultCode == RESULT_OK && data != null) {
            final DialServer dialServer = data.getParcelableExtra(ServerFinder.EXTRA_DIAL_SERVER);
            if (dialServer != null) {
                Toast.makeText(MainActivity.this, getString(R.string.finder_connected, dialServer.toString()),
                        Toast.LENGTH_LONG).show();
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            String device = "http://" + dialServer.getIpAddress().getHostAddress() + ":"
                                    + dialServer.getPort();
                            Log.d(LOG_TAG, "device=" + device);
                            Log.d(LOG_TAG, "apps url=" + dialServer.getAppsUrl());

                            // application instance url
                            String location = null;
                            String app = YOU_TUBE;

                            DefaultHttpClient defaultHttpClient = HttpRequestHelper.createHttpClient();
                            CustomRedirectHandler handler = new CustomRedirectHandler();
                            defaultHttpClient.setRedirectHandler(handler);
                            BasicHttpContext localContext = new BasicHttpContext();

                            // check if any app is running
                            HttpGet httpGet = new HttpGet(dialServer.getAppsUrl());
                            httpGet.setHeader(HEADER_CONNECTION, HEADER_CONNECTION_VALUE);
                            httpGet.setHeader(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE);
                            httpGet.setHeader(HEADER_ACCEPT, HEADER_ACCEPT_VALUE);
                            httpGet.setHeader(HEADER_DNT, HEADER_DNT_VALUE);
                            httpGet.setHeader(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE);
                            httpGet.setHeader(HEADER_ACCEPT_LANGUAGE, HEADER_ACCEPT_LANGUAGE_VALUE);
                            HttpResponse httpResponse = defaultHttpClient.execute(httpGet);
                            if (httpResponse != null) {
                                int responseCode = httpResponse.getStatusLine().getStatusCode();
                                Log.d(LOG_TAG,
                                        "get response code=" + httpResponse.getStatusLine().getStatusCode());
                                if (responseCode == 204) {
                                    // nothing is running
                                } else if (responseCode == 200) {
                                    // app is running

                                    // Need to get real URL after a redirect
                                    // http://stackoverflow.com/a/10286025/594751
                                    String lastUrl = dialServer.getAppsUrl();
                                    if (handler.lastRedirectedUri != null) {
                                        lastUrl = handler.lastRedirectedUri.toString();
                                        Log.d(LOG_TAG, "lastUrl=" + lastUrl);
                                    }//from   w w w .j av  a2s  . co  m

                                    String response = EntityUtils.toString(httpResponse.getEntity());
                                    Log.d(LOG_TAG, "get response=" + response);
                                    parseXml(MainActivity.this, new StringReader(response));

                                    Header[] headers = httpResponse.getAllHeaders();
                                    for (int i = 0; i < headers.length; i++) {
                                        Log.d(LOG_TAG, headers[i].getName() + "=" + headers[i].getValue());
                                    }

                                    // stop the app instance
                                    HttpDelete httpDelete = new HttpDelete(lastUrl);
                                    httpResponse = defaultHttpClient.execute(httpDelete);
                                    if (httpResponse != null) {
                                        Log.d(LOG_TAG, "delete response code="
                                                + httpResponse.getStatusLine().getStatusCode());
                                        response = EntityUtils.toString(httpResponse.getEntity());
                                        Log.d(LOG_TAG, "delete response=" + response);
                                    } else {
                                        Log.d(LOG_TAG, "no delete response");
                                    }
                                }

                            } else {
                                Log.i(LOG_TAG, "no get response");
                                return;
                            }

                            // Check if app is installed on device
                            int responseCode = getAppStatus(defaultHttpClient, dialServer.getAppsUrl() + app);
                            if (responseCode != 200) {
                                return;
                            }
                            parseXml(MainActivity.this, new StringReader(response));
                            Log.d(LOG_TAG, "state=" + state);

                            // start the app with POST
                            HttpPost httpPost = new HttpPost(dialServer.getAppsUrl() + app);
                            httpPost.setHeader(HEADER_CONNECTION, HEADER_CONNECTION_VALUE);
                            httpPost.setHeader(HEADER_ORIGN, HEADER_ORIGIN_VALUE);
                            httpPost.setHeader(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE);
                            httpPost.setHeader(HEADER_DNT, HEADER_DNT_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT, HEADER_ACCEPT_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT_LANGUAGE, HEADER_ACCEPT_LANGUAGE_VALUE);
                            httpPost.setHeader(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_TEXT_VALUE);
                            // Set variable values as the body of the POST;
                            // v is the YouTube video id.
                            httpPost.setEntity(new StringEntity(
                                    "pairingCode=eac4ae42-8b54-4441-9be3-d8a9abb5c481&v=cKG5HDyTW8o&t=0")); // http://www.youtube.com/watch?v=cKG5HDyTW8o

                            httpResponse = defaultHttpClient.execute(httpPost, localContext);
                            if (httpResponse != null) {
                                Log.d(LOG_TAG,
                                        "post response code=" + httpResponse.getStatusLine().getStatusCode());
                                response = EntityUtils.toString(httpResponse.getEntity());
                                Log.d(LOG_TAG, "post response=" + response);
                                Header[] headers = httpResponse.getHeaders("LOCATION");
                                if (headers.length > 0) {
                                    location = headers[0].getValue();
                                    Log.d(LOG_TAG, "post response location=" + location);
                                }

                                headers = httpResponse.getAllHeaders();
                                for (int i = 0; i < headers.length; i++) {
                                    Log.d(LOG_TAG, headers[i].getName() + "=" + headers[i].getValue());
                                }
                            } else {
                                Log.i(LOG_TAG, "no post response");
                                return;
                            }

                            // Keep trying to get the app status until the
                            // connection service URL is available
                            state = STATE_STOPPED;
                            do {
                                responseCode = getAppStatus(defaultHttpClient, dialServer.getAppsUrl() + app);
                                if (responseCode != 200) {
                                    break;
                                }
                                parseXml(MainActivity.this, new StringReader(response));
                                Log.d(LOG_TAG, "state=" + state);
                                Log.d(LOG_TAG, "connectionServiceUrl=" + connectionServiceUrl);
                                Log.d(LOG_TAG, "protocol=" + protocol);
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {
                                }
                            } while (state.equals(STATE_RUNNING) && connectionServiceUrl == null);

                            if (connectionServiceUrl == null) {
                                Log.i(LOG_TAG, "connectionServiceUrl is null");
                                return; // oops, something went wrong
                            }

                            // get the websocket URL
                            String webSocketAddress = null;
                            httpPost = new HttpPost(connectionServiceUrl); // "http://192.168.0.17:8008/connection/YouTube"
                            httpPost.setHeader(HEADER_CONNECTION, HEADER_CONNECTION_VALUE);
                            httpPost.setHeader(HEADER_ORIGN, HEADER_ORIGIN_VALUE);
                            httpPost.setHeader(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE);
                            httpPost.setHeader(HEADER_DNT, HEADER_DNT_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT, HEADER_ACCEPT_VALUE);
                            httpPost.setHeader(HEADER_ACCEPT_LANGUAGE, HEADER_ACCEPT_LANGUAGE_VALUE);
                            httpPost.setHeader(HEADER_CONTENT_TYPE, HEADER_CONTENT_TYPE_JSON_VALUE);
                            httpPost.setEntity(new StringEntity(
                                    "{\"channel\":0,\"senderId\":{\"appName\":\"ChromeCast\", \"senderId\":\"7v3zqrpliq3i\"}}"));

                            httpResponse = defaultHttpClient.execute(httpPost, localContext);
                            if (httpResponse != null) {
                                responseCode = httpResponse.getStatusLine().getStatusCode();
                                Log.d(LOG_TAG, "post response code=" + responseCode);
                                if (responseCode == 200) {
                                    // should return JSON payload
                                    response = EntityUtils.toString(httpResponse.getEntity());
                                    Log.d(LOG_TAG, "post response=" + response);
                                    Header[] headers = httpResponse.getAllHeaders();
                                    for (int i = 0; i < headers.length; i++) {
                                        Log.d(LOG_TAG, headers[i].getName() + "=" + headers[i].getValue());
                                    }

                                    JSONObject jObject;
                                    try {
                                        jObject = new JSONObject(response); // {"URL":"ws://192.168.0.17:8008/session?33","pingInterval":0}
                                        webSocketAddress = jObject.getString("URL");
                                        Log.d(LOG_TAG, "webSocketAddress: " + webSocketAddress);
                                        int pingInterval = jObject.optInt("pingInterval"); // TODO
                                    } catch (JSONException e) {
                                        Log.e(LOG_TAG, "JSON", e);
                                    }
                                }
                            } else {
                                Log.i(LOG_TAG, "no post response");
                                return;
                            }

                            // Make a web socket connection for doing RAMP
                            // to control media playback
                            if (webSocketAddress != null) {
                                // https://github.com/koush/android-websockets
                                List<BasicNameValuePair> extraHeaders = Arrays.asList(
                                        new BasicNameValuePair(HEADER_ORIGN, HEADER_ORIGIN_VALUE),
                                        new BasicNameValuePair("Pragma", "no-cache"),
                                        new BasicNameValuePair("Cache-Control", "no-cache"),
                                        new BasicNameValuePair(HEADER_USER_AGENT, HEADER_USER_AGENT_VALUE));
                                client = new WebSocketClient(URI.create(webSocketAddress),
                                        new WebSocketClient.Listener() { // ws://192.168.0.17:8008/session?26
                                            @Override
                                            public void onConnect() {
                                                Log.d(LOG_TAG, "Websocket Connected!");

                                                // TODO RAMP commands
                                            }

                                            @Override
                                            public void onMessage(String message) {
                                                Log.d(LOG_TAG, String.format("Websocket Got string message! %s",
                                                        message));
                                            }

                                            @Override
                                            public void onMessage(byte[] data) {
                                                Log.d(LOG_TAG, String.format("Websocket Got binary message! %s",
                                                        data));
                                            }

                                            @Override
                                            public void onDisconnect(int code, String reason) {
                                                Log.d(LOG_TAG,
                                                        String.format(
                                                                "Websocket Disconnected! Code: %d Reason: %s",
                                                                code, reason));
                                            }

                                            @Override
                                            public void onError(Exception error) {
                                                Log.e(LOG_TAG, "Websocket Error!", error);
                                            }

                                        }, extraHeaders);
                                client.connect();
                            } else {
                                Log.i(LOG_TAG, "webSocketAddress is null");
                            }

                        } catch (Exception e) {
                            Log.e(LOG_TAG, "run", e);
                        }
                    }
                }).start();
            }
        }
    }
}

From source file:eu.alefzero.owncloud.files.services.InstantUploadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || !intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_DISPLAY_NAME)
            || !intent.hasExtra(KEY_FILE_PATH) || !intent.hasExtra(KEY_FILE_SIZE)
            || !intent.hasExtra(KEY_MIME_TYPE)) {
        Log.w(TAG, "Not all required information was provided, abording");
        return Service.START_NOT_STICKY;
    }//  w w w .ja va2s  .c om

    if (mUploaderRunnable == null) {
        mUploaderRunnable = new UploaderRunnable();
    }

    String filename = intent.getStringExtra(KEY_DISPLAY_NAME);
    String filepath = intent.getStringExtra(KEY_FILE_PATH);
    String mimetype = intent.getStringExtra(KEY_MIME_TYPE);
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    long filesize = intent.getLongExtra(KEY_FILE_SIZE, -1);

    mUploaderRunnable.addElementToQueue(filename, filepath, mimetype, filesize, account);

    // starting new thread for new download doesnt seems like a good idea
    // maybe some thread pool or single background thread would be better
    Log.d(TAG, "Starting instant upload thread");
    new Thread(mUploaderRunnable).start();

    return Service.START_STICKY;
}

From source file:de.mangelow.throughput.NotificationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (intent != null)
        mResultReceiver = intent.getParcelableExtra("receiver");

    return START_STICKY;
}

From source file:com.digitalarx.android.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 * //from ww  w.  ja  va 2s.  c  om
 * New downloads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working 
 * although the caller activity goes away.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)
    /*!intent.hasExtra(EXTRA_FILE_PATH) ||
    !intent.hasExtra(EXTRA_REMOTE_PATH)*/
    ) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
    OCFile file = intent.getParcelableExtra(EXTRA_FILE);

    AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
    String downloadKey = buildRemoteName(account, file);
    try {
        DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
        mPendingDownloads.putIfAbsent(downloadKey, newDownload);
        newDownload.addDatatransferProgressListener(this);
        newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
        requestedDownloads.add(downloadKey);
        sendBroadcastNewDownload(newDownload);

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;
    }

    if (requestedDownloads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedDownloads;
        mServiceHandler.sendMessage(msg);
    }

    return START_NOT_STICKY;
}

From source file:cn.figo.mydemo.ui.activity.VideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mSettings = new Settings(this);

    //      handle arguments
    mVideoPath = getIntent().getStringExtra("videoPath");

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        String scheme = mVideoUri.getScheme();
        if (TextUtils.isEmpty(scheme)) {
            Log.e(TAG, "Null unknown ccheme\n");
            finish();//w  w w .  ja v a  2  s  .  com
            return;
        }
        if (scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE)) {
            mVideoPath = mVideoUri.getPath();
        } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
            Log.e(TAG, "Can not resolve content below Android-ICS\n");
            finish();
            return;
        } else {
            Log.e(TAG, "Unknown scheme " + scheme + "\n");
            finish();
            return;
        }
    }

    Intent intent = getIntent();
    String intentAction = intent.getAction();
    if (!TextUtils.isEmpty(intentAction)) {
        if (intentAction.equals(Intent.ACTION_VIEW)) {
            mVideoPath = intent.getDataString();
        } else if (intentAction.equals(Intent.ACTION_SEND)) {
            mVideoUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                String scheme = mVideoUri.getScheme();
                if (TextUtils.isEmpty(scheme)) {
                    Log.e(TAG, "Null unknown ccheme\n");
                    finish();
                    return;
                }
                if (scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE)) {
                    mVideoPath = mVideoUri.getPath();
                } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
                    Log.e(TAG, "Can not resolve content below Android-ICS\n");
                    finish();
                    return;
                } else {
                    Log.e(TAG, "Unknown scheme " + scheme + "\n");
                    finish();
                    return;
                }
            }
        }
    }

    if (!TextUtils.isEmpty(mVideoPath)) {
        new RecentMediaStorage(this).saveUrlAsync(mVideoPath);
    }

    // init UI
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    mMediaController = new AndroidMediaController(this, false);
    mMediaController.setSupportActionBar(actionBar);

    mToastTextView = (TextView) findViewById(R.id.toast_text_view);
    mHudView = (TableLayout) findViewById(R.id.hud_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mRightDrawer = (ViewGroup) findViewById(R.id.right_drawer);

    mDrawerLayout.setScrimColor(Color.TRANSPARENT);

    new RecentMediaStorage(this).saveUrlAsync(mVideoPath);

    // init player
    IjkMediaPlayer.loadLibrariesOnce(null);
    IjkMediaPlayer.native_profileBegin("libijkplayer.so");

    mVideoView = (IjkVideoView) findViewById(R.id.video_view);
    mVideoView.setMediaController(mMediaController);
    mVideoView.setHudView(mHudView);

    mVideoView.toggleAspectRatio();

    if (mVideoPath != null)
        mVideoView.setVideoPath(mVideoPath);
    else if (mVideoUri != null)
        mVideoView.setVideoURI(mVideoUri);
    else {
        Log.e(TAG, "Null Data Source\n");
        finish();
        return;
    }

    initDanmaku();

}

From source file:com.example.linhdq.test.documents.viewing.grid.DocumentGridActivity.java

private void checkForImageIntent(Intent intent) {

    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (imageUri != null) {
            loadBitmapFromContentUri(imageUri, ImageSource.INTENT);
        } else {/* www  .j av a2s .  c  o  m*/
            showFileError(PixLoadStatus.IMAGE_COULD_NOT_BE_READ, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
        }

    }
}

From source file:com.markupartist.sthlmtraveling.PlaceSearchActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CODE_POINT_ON_MAP:
        if (resultCode != Activity.RESULT_CANCELED) {
            Site place = data.getParcelableExtra(PointOnMapActivity.EXTRA_STOP);
            if (!place.hasName()) {
                place.setName(getString(R.string.point_on_map));
            }//  www. ja v a 2  s  .  c  o  m
            deliverResult(place);
        }
        break;
    }
}

From source file:com.owncloud.android.services.observer.FileObserverService.java

/**
 * Handles requests to://from w  w  w .  ja  v a2s  . co  m
 *  - (re)start watching                    (ACTION_START_OBSERVE)
 *  - add an {@link OCFile} to be watched   (ATION_ADD_OBSERVED_FILE)
 *  - stop observing an {@link OCFile}      (ACTION_DEL_OBSERVED_FILE) 
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command " + intent);

    if (intent == null || ACTION_START_OBSERVE.equals(intent.getAction())) {
        // NULL occurs when system tries to restart the service after its
        // process was killed
        startObservation();
        return Service.START_STICKY;

    } else if (ACTION_ADD_OBSERVED_FILE.equals(intent.getAction())) {
        OCFile file = intent.getParcelableExtra(ARG_FILE);
        Account account = intent.getParcelableExtra(ARG_ACCOUNT);
        addObservedFile(file, account);

    } else if (ACTION_DEL_OBSERVED_FILE.equals(intent.getAction())) {
        removeObservedFile((OCFile) intent.getParcelableExtra(ARG_FILE),
                (Account) intent.getParcelableExtra(ARG_ACCOUNT));

    } else if (ACTION_UPDATE_AUTO_UPLOAD_OBSERVERS.equals(intent.getAction())) {
        updateInstantUploadsObservers();

    } else {
        Log_OC.e(TAG, "Unknown action received; ignoring it: " + intent.getAction());
    }

    return Service.START_STICKY;
}

From source file:com.example.trumpetproject.activities.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // will be triggered in response to User Popup(save/not save) decision
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);

    if (requestCode == RC_READ) {
        // in case of multiple credentials...this will read what cred user clicked on
        if (resultCode == RESULT_OK) {
            // successfully read Cred - now compare them to DB
            Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
            processRetrievedCredential(credential);
        } else {/*from  ww  w. jav  a2  s . c o  m*/
            Log.e(TAG, "Credential Read: NOT OK");
            setSignInEnabled(true);
        }
    } else if (requestCode == RC_SAVE) {
        // requestCode is RC_SAVE indicates Secure Lock made a REQUEST/asked the user if he wants to save or not.
        Log.d(TAG, "Result code: " + resultCode);
        if (resultCode == RESULT_OK) {
            Log.d(TAG, "Credential Save: OK"); // user selected to save Cred
        } else {
            Log.e(TAG, "Credential Save Failed"); // user selected not to save Cred.
        }
        goToContent();
    }
    mIsResolving = false;
}

From source file:com.phonegap.plugins.blinkid.BlinkIdScanner.java

/**
 * Called when the scanner intent completes.
 * /*from  w ww. j  a  va  2 s  .  c  om*/
 * @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").
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == REQUEST_CODE) {

        if (resultCode == ScanCard.RESULT_OK) {

            // First, obtain recognition result
            RecognitionResults results = data.getParcelableExtra(ScanCard.EXTRAS_RECOGNITION_RESULTS);
            // Get scan results array. If scan was successful, array will contain at least one element.
            // Multiple element may be in array if multiple scan results from single image were allowed in settings.
            BaseRecognitionResult[] resultArray = results.getRecognitionResults();

            // Each recognition result corresponds to active recognizer. There are 7 types of
            // recognizers available (PDF417, USDL, Bardecoder, ZXing, MRTD, UKDL and MyKad),
            // so there are 7 types of results available.

            JSONArray resultsList = new JSONArray();

            for (BaseRecognitionResult res : resultArray) {
                try {
                    if (res instanceof Pdf417ScanResult) { // check if scan result is result of Pdf417 recognizer
                        resultsList.put(buildPdf417Result((Pdf417ScanResult) res));
                    } else if (res instanceof BarDecoderScanResult) { // check if scan result is result of BarDecoder recognizer
                        resultsList.put(buildBarDecoderResult((BarDecoderScanResult) res));
                    } else if (res instanceof ZXingScanResult) { // check if scan result is result of ZXing recognizer
                        resultsList.put(buildZxingResult((ZXingScanResult) res));
                    } else if (res instanceof MRTDRecognitionResult) { // check if scan result is result of MRTD recognizer
                        resultsList.put(buildMRTDResult((MRTDRecognitionResult) res));
                    } else if (res instanceof USDLScanResult) { // check if scan result is result of US Driver's Licence recognizer
                        resultsList.put(buildUSDLResult((USDLScanResult) res));
                    } else if (res instanceof EUDLRecognitionResult) { // check if scan result is result of EUDL recognizer
                        resultsList.put(buildUKDLResult((EUDLRecognitionResult) res));
                    } else if (res instanceof MyKadRecognitionResult) { // check if scan result is result of MyKad recognizer
                        resultsList.put(buildMyKadResult((MyKadRecognitionResult) res));
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "Error parsing " + res.getClass().getName());
                }
            }

            try {
                JSONObject root = new JSONObject();
                root.put(RESULT_LIST, resultsList);
                if (mImageType != IMAGE_NONE) {
                    Image resultImage = ImageHolder.getInstance().getLastImage();
                    if (resultImage != null) {
                        Bitmap resultImgBmp = resultImage.convertToBitmap();
                        if (resultImgBmp != null) {
                            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                            boolean success = resultImgBmp.compress(Bitmap.CompressFormat.JPEG,
                                    COMPRESSED_IMAGE_QUALITY, byteArrayOutputStream);
                            if (success) {
                                String resultImgBase64 = Base64
                                        .encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
                                root.put(RESULT_IMAGE, resultImgBase64);
                            }
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException ignorable) {
                            }
                        }
                        ImageHolder.getInstance().clear();
                    }
                }
                root.put(CANCELLED, false);
                this.callbackContext.success(root);
            } catch (JSONException e) {
                Log.e(LOG_TAG, "This should never happen");
            }

        } else if (resultCode == ScanCard.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(CANCELLED, true);

            } catch (JSONException e) {
                Log.e(LOG_TAG, "This should never happen");
            }
            this.callbackContext.success(obj);

        } else {
            this.callbackContext.error("Unexpected error");
        }
    }
}