Example usage for android.content Intent getBooleanExtra

List of usage examples for android.content Intent getBooleanExtra

Introduction

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

Prototype

public boolean getBooleanExtra(String name, boolean defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.cerema.cloud2.files.services.FileUploader.java

/**
 * Entry point to add one or several files to the queue of uploads.
 *
 * New uploads 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.//  w w  w.  j  ava  2  s .c  o m
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)) {
        Account account = intent.getParcelableExtra(KEY_ACCOUNT);

        if (mCurrentUpload != null) {
            FileUploaderBinder fub = (FileUploaderBinder) mBinder;
            fub.cancel(account);
            return Service.START_NOT_STICKY;
        }
    }

    if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE)
            || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return Service.START_NOT_STICKY;
    }
    int uploadType = intent.getIntExtra(KEY_UPLOAD_TYPE, -1);
    if (uploadType == -1) {
        Log_OC.e(TAG, "Incorrect upload type provided");
        return Service.START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    if (!AccountUtils.exists(account, getApplicationContext())) {
        return Service.START_NOT_STICKY;
    }

    String[] localPaths = null, remotePaths = null, mimeTypes = null;
    OCFile[] files = null;
    if (uploadType == UPLOAD_SINGLE_FILE) {

        if (intent.hasExtra(KEY_FILE)) {
            files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };

        } else {
            localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
            remotePaths = new String[] { intent.getStringExtra(KEY_REMOTE_FILE) };
            mimeTypes = new String[] { intent.getStringExtra(KEY_MIME_TYPE) };
        }

    } else { // mUploadType == UPLOAD_MULTIPLE_FILES

        if (intent.hasExtra(KEY_FILE)) {
            files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO
                                                                         // will
                                                                         // this
                                                                         // casting
                                                                         // work
                                                                         // fine?

        } else {
            localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE);
            remotePaths = intent.getStringArrayExtra(KEY_REMOTE_FILE);
            mimeTypes = intent.getStringArrayExtra(KEY_MIME_TYPE);
        }
    }

    FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());

    boolean forceOverwrite = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false);
    boolean isInstant = intent.getBooleanExtra(KEY_INSTANT_UPLOAD, false);
    int localAction = intent.getIntExtra(KEY_LOCAL_BEHAVIOUR, LOCAL_BEHAVIOUR_FORGET);

    if (intent.hasExtra(KEY_FILE) && files == null) {
        Log_OC.e(TAG, "Incorrect array for OCFiles provided in upload intent");
        return Service.START_NOT_STICKY;

    } else if (!intent.hasExtra(KEY_FILE)) {
        if (localPaths == null) {
            Log_OC.e(TAG, "Incorrect array for local paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (remotePaths == null) {
            Log_OC.e(TAG, "Incorrect array for remote paths provided in upload intent");
            return Service.START_NOT_STICKY;
        }
        if (localPaths.length != remotePaths.length) {
            Log_OC.e(TAG, "Different number of remote paths and local paths!");
            return Service.START_NOT_STICKY;
        }

        files = new OCFile[localPaths.length];
        for (int i = 0; i < localPaths.length; i++) {
            files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i],
                    ((mimeTypes != null) ? mimeTypes[i] : null));
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    OwnCloudVersion ocv = AccountUtils.getServerVersion(account);

    boolean chunked = FileUploader.chunkedUploadIsSupported(ocv);
    AbstractList<String> requestedUploads = new Vector<String>();
    String uploadKey = null;
    UploadFileOperation newUpload = null;
    try {
        for (int i = 0; i < files.length; i++) {
            newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite,
                    localAction, getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            Pair<String, String> putResult = mPendingUploads.putIfAbsent(account, files[i].getRemotePath(),
                    newUpload);
            if (putResult != null) {
                uploadKey = putResult.first;
                requestedUploads.add(uploadKey);
            } // else, file already in the queue of uploads; don't repeat the request
        }

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

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

    } catch (Exception e) {
        Log_OC.e(TAG, "Unexpected exception while processing upload intent", e);
        return START_NOT_STICKY;

    }

    if (requestedUploads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedUploads;
        mServiceHandler.sendMessage(msg);
    }
    return Service.START_NOT_STICKY;
}

From source file:com.httrack.android.HTTrackActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    Log.d(getClass().getSimpleName(), "onActivityResult");
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case ACTIVITY_OPTIONS:
        if (resultCode == Activity.RESULT_OK) {
            // Load modified map
            loadParcelable(data.getParcelableExtra("com.httrack.android.map"));
        }//from w  w w.ja v  a  2s . c  om
        break;
    case ACTIVITY_FILE_CHOOSER:
        if (resultCode == Activity.RESULT_OK) {
            // Load modified map
            final String path = data.getStringExtra("com.httrack.android.rootFile");
            setBasePath(path);
        }
        break;
    case ACTIVITY_PROJECT_NAME_CHOOSER:
        if (resultCode == Activity.RESULT_OK) {
            final String projectName = data.getStringExtra("com.httrack.android.projectName");
            final EditText name = EditText.class.cast(this.findViewById(R.id.fieldProjectName));
            name.setText(projectName);
            name.setSelection(projectName.length());
            name.requestFocus();
        }
        break;
    case ACTIVITY_CLEANUP:
        if (resultCode == Activity.RESULT_OK) {
            final boolean rootWasDeleted = data.getBooleanExtra("com.httrack.android.rootPathWasDeleted",
                    false);
            // Exit because otherwise we can't recreate the directory (!)
            if (rootWasDeleted && android.os.Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
                Log.w("httrack", "exiting because root path was deleted (Android >= Kitkat issue)");
                // restartActivity();
                finish();
                // darn, this is not clean, but otherwise restarting the activity
                // won't be enough. I suspect FUSE-related issue here
                System.exit(0);
            }
        }
        break;
    }
}

From source file:com.andrew.apollo.MusicPlaybackService.java

/**
 * {@inheritDoc}//from  w w w .j ava 2 s  .com
 */
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (D)
        LOG.info("Got new intent " + intent + ", startId = " + startId);
    mServiceStartId = startId;

    if (intent != null) {
        final String action = intent.getAction();

        if (intent.hasExtra(NOW_IN_FOREGROUND)) {
            musicPlaybackActivityInForeground = intent.getBooleanExtra(NOW_IN_FOREGROUND, false);
            updateNotification();
        }

        if (SHUTDOWN_ACTION.equals(action)) {
            cancelShutdown();
            exiting = intent.hasExtra("force");
            releaseServiceUiAndStop(exiting);
            return START_NOT_STICKY;
        }

        handleCommandIntent(intent);
    }

    // Make sure the service will shut down on its own if it was
    // just started but not bound to and nothing is playing
    scheduleDelayedShutdown();

    if (intent != null && intent.getBooleanExtra(FROM_MEDIA_BUTTON, false)) {
        MediaButtonIntentReceiver.completeWakefulIntent(intent);
    }

    return START_STICKY;
}

From source file:com.av.remusic.service.MediaService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (D)/*from w  w w .j  a v a 2 s .  c o m*/
        Log.d(TAG, "Got new intent " + intent + ", startId = " + startId);
    mServiceStartId = startId;
    if (intent != null) {
        final String action = intent.getAction();

        if (SHUTDOWN.equals(action)) {
            mShutdownScheduled = false;
            releaseServiceUiAndStop();
            return START_NOT_STICKY;
        }
        handleCommandIntent(intent);
    }

    scheduleDelayedShutdown();

    if (intent != null && intent.getBooleanExtra(FROM_MEDIA_BUTTON, false)) {
        MediaButtonIntentReceiver.completeWakefulIntent(intent);
    }
    return START_STICKY;
}

From source file:com.example.mysteryhunt.MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case 1:/*  ww  w  .j a  v a 2s. c  om*/
        // Register user
        if (resultCode == RESULT_OK) {
            String name = data.getStringExtra("name");
            if (!name.isEmpty()) {
                inUsername.setText(name);
                inPassword.setText("");
                inPassword.requestFocus();
            }
            String userPasswd = data.getStringExtra("password");
            if (!userPasswd.isEmpty()) {
                inPassword.setText(userPasswd);
            }
            if (!name.isEmpty() && !userPasswd.isEmpty()) {
                // We have the user details, so sign in!
                username = name;
                password = userPasswd;
                AppHelper.getPool().getUser(username).getSessionInBackground(authenticationHandler);
            }
        }
        break;
    case 2:
        // Confirm register user
        if (resultCode == RESULT_OK) {
            String name = data.getStringExtra("name");
            if (!name.isEmpty()) {
                inUsername.setText(name);
                inPassword.setText("");
                inPassword.requestFocus();
            }
        }
        break;
    case 3:
        // Forgot password
        if (resultCode == RESULT_OK) {
            String newPass = data.getStringExtra("newPass");
            String code = data.getStringExtra("code");
            if (newPass != null && code != null) {
                if (!newPass.isEmpty() && !code.isEmpty()) {
                    showWaitDialog("Setting new password...");
                    forgotPasswordContinuation.setPassword(newPass);
                    forgotPasswordContinuation.setVerificationCode(code);
                    forgotPasswordContinuation.continueTask();
                }
            }
        }
        break;
    case 4:
        // User
        if (resultCode == RESULT_OK) {
            clearInput();
            String name = data.getStringExtra("TODO");
            if (name != null) {
                if (!name.isEmpty()) {
                    name.equals("exit");
                    onBackPressed();
                }
            }
        }
        break;
    case 5:
        //MFA
        closeWaitDialog();
        if (resultCode == RESULT_OK) {
            String code = data.getStringExtra("mfacode");
            if (code != null) {
                if (code.length() > 0) {
                    showWaitDialog("Signing in...");
                    multiFactorAuthenticationContinuation.setMfaCode(code);
                    multiFactorAuthenticationContinuation.continueTask();
                } else {
                    inPassword.setText("");
                    inPassword.requestFocus();
                }
            }
        }
        break;
    case 6:
        //New password
        closeWaitDialog();
        Boolean continueSignIn = false;
        if (resultCode == RESULT_OK) {
            continueSignIn = data.getBooleanExtra("continueSignIn", false);
        }
        if (continueSignIn) {
            continueWithFirstTimeSignIn();
        }
    }
}

From source file:com.ruesga.rview.fragments.ChangeDetailsFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == DIFF_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            // Current revision
            String revisionId = data.getStringExtra(Constants.EXTRA_REVISION_ID);
            if (revisionId != null && !revisionId.equals(mCurrentRevision)) {
                // Change to the current revision
                mCurrentRevision = revisionId;
                forceRefresh();/*from  w  w w. j  a  va  2  s .  c  o  m*/
                return;
            }

            // Diff against revision
            String diffAgainst = resolveDiffAgainstRevision(data.getStringExtra(Constants.EXTRA_BASE));
            boolean changed = (diffAgainst == null && mDiffAgainstRevision != null)
                    || (diffAgainst != null && mDiffAgainstRevision == null)
                    || (diffAgainst != null && !diffAgainst.equals(mDiffAgainstRevision));
            if (changed) {
                // Change to the diff against revision revision
                if (diffAgainst != null && diffAgainst.equals(mCurrentRevision)) {
                    mDiffAgainstRevision = null;
                } else {
                    mDiffAgainstRevision = diffAgainst;
                }
                forceRefresh();
                return;
            }

            // Drafts changed
            boolean dataChanged = data.getBooleanExtra(Constants.EXTRA_DATA_CHANGED, false);
            if (dataChanged) {
                // Refresh drafts comments
                performDraftsRefresh();
            }
        }
    } else if (requestCode == EDIT_REQUEST_CODE) {
        // Remove the cache, in case the user request to enter again in edit mode
        CacheHelper.removeAccountDiffCacheDir(getContext());

        // If the user publish the edit, then reload the whole change
        if (resultCode == Activity.RESULT_OK) {
            mCurrentRevision = null;
            mDiffAgainstRevision = null;
            forceRefresh();
        }
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;/*from  ww  w . j a  va2  s . c  o m*/
    path = i.getStringExtra("path");

    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                MainFragment m = ((MainFragment) getFragment().getTab());
                m.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {

        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);

    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer(), KEY_INTENT_PROCESS_VIEWER);
        //   transaction.addToBackStack(null);
        selectedStorage = SELECT_102;
        openProcesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }

        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (sharedPref.getString(KEY_PREF_OTG, null) == null) {
                    sharedPref.edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                sharedPref.edit().putString(KEY_PREF_OTG, null).apply();
                refreshDrawer();
            }
        }
    }
}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (LOCAL_LOGV)
        log("onStartCommand()", "v");

    //check if resuming after close for memory, or other crash
    if ((flags & Service.START_FLAG_REDELIVERY) != 0) {
        //maybe handle this with dialog and tap to resume
        if (LOCAL_LOGD)
            log("Intent redelivery, restarting", "d");
    }/*w  ww .j av  a2 s .c om*/

    mIntent = intent;
    if (intent == null) {
        if (LOCAL_LOGD)
            log("No intent", "w");
    } else {
        String action = intent.getAction();
        if (action == null) {
            if (LOCAL_LOGD)
                log("No action specified", "w"); //why?
            //return flag indicating no further action needed if service is stopped by system and later resumes
            return START_NOT_STICKY;
        } else if (action.equals(Intent.ACTION_RUN)) //called when service is being bound by player activity
        {
            if (LOCAL_LOGV)
                log("service being started probably so it can be bound", "v");
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PLAY.toString())) //Play intent
        {
            int preset = Integer.valueOf(intent.getIntExtra(ActivityMain.EXTRA_STATION_PRESET, 0));
            if (LOCAL_LOGD)
                log("PLAY action in intent. Preset in extra:" + String.valueOf(preset), "d");
            play(preset);
            //return START_REDELIVER_INTENT;
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PLAY_STREAM.toString())) //Play intent
        {
            if (LOCAL_LOGV)
                log("PLAY_STREAM action in intent", "v");
            String url = intent.getStringExtra(EXTRA_URL);
            if (LOCAL_LOGD)
                log("URL in extra:" + url, "d");
            //check whether the url should be updated (for metadata retrieval purposes)
            boolean updateUrl = intent.getBooleanExtra(EXTRA_UPDATE_URL, false);
            if (updateUrl) {
                mUrl = url;
            }
            playUrl(url);
            //return START_REDELIVER_INTENT;
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_UNSUPPORTED_FORMAT_ERROR.toString())) {

            String format = intent.getStringExtra(EXTRA_FORMAT);
            if (LOCAL_LOGD)
                log("Known unsupported format: " + format, "d");
            String title = getResources().getString(R.string.error_title);
            String message = getResources().getString(R.string.error_format) + ":" + format;
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_FORMAT_ERROR.toString())) {
            String message = intent.getStringExtra(EXTRA_ERROR_MESSAGE);
            if (LOCAL_LOGD)
                log("URL was unable to play:" + message, "d");
            String title = getResources().getString(R.string.error_title);
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_STREAM_ERROR.toString())) {

            int responseCode = intent.getIntExtra(EXTRA_RESPONSE_CODE, 0);
            String responseMessage = intent.getStringExtra(EXTRA_RESPONSE_MESSAGE);
            if (LOCAL_LOGD)
                log("Stream error. Code:" + String.valueOf(responseCode) + ", Message:" + responseMessage, "d");
            String title = getResources().getString(R.string.error_title);
            String message;
            switch (responseCode) {
            case 404:
                message = getResources().getString(R.string.error_not_found);
                break;
            case 400:
                if (responseMessage.equals("Server Full")) {
                    message = getResources().getString(R.string.error_server_full);
                } else {
                    message = getResources().getString(R.string.error_unknown);
                }
                break;
            default:
                message = getResources().getString(R.string.error_unknown);
            }
            mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
            //set 'now playing' to error
            stopInfo(getResources().getString(R.string.status_error));
            this.getErrorNotification(title, message);
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_NEXT.toString())) //Next preset intent
        {
            if (LOCAL_LOGD)
                log("NEXT action in intent", "d");
            nextPreset();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PREVIOUS.toString())) //Previous preset intent
        {
            if (LOCAL_LOGD)
                log("PREVIOUS action in intent", "d");
            previousPreset();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_STOP.toString())) //Stop intent
        {
            if (LOCAL_LOGD)
                log("STOP action in intent", "d");
            end();
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_LIKE.toString())) //Stop intent
        {
            if (intent.hasExtra(EXTRA_SET_TRUE)) {
                boolean set = intent.getBooleanExtra(EXTRA_SET_TRUE, false);
                if (set) {
                    if (LOCAL_LOGD)
                        log("LIKE action in intent with true", "d");
                    this.like();
                } else {
                    if (LOCAL_LOGD)
                        log("LIKE action in intent with false", "d");
                    this.unlike();
                }
            }

            return START_NOT_STICKY;
        } else if (action.equals(ACTION_DISLIKE.toString())) //Stop intent
        {
            if (intent.hasExtra(EXTRA_SET_TRUE)) {
                boolean set = intent.getBooleanExtra(EXTRA_SET_TRUE, true);
                if (set) {
                    if (LOCAL_LOGD)
                        log("DISLIKE action in intent with true", "d");
                    this.dislike();
                } else {
                    if (LOCAL_LOGD)
                        log("DISLIKE action in intent with false", "d");
                    this.undislike();
                }
            }
            return START_NOT_STICKY;
        } else if (action.equals(ACTION_PULL_WIDGET_INFO.toString())) {
            if (LOCAL_LOGV)
                log("UPDATE_WIDGET action in intent", "v");
            updateDetails();
            endIfNotNeeded();

            return START_NOT_STICKY;
        } else {
            log("Unknown Action:" + action, "w");
        }
    }

    //return START_STICKY;
    return START_NOT_STICKY;
    //return START_REDELIVER_INTENT;
}