Example usage for android.content Intent getLongExtra

List of usage examples for android.content Intent getLongExtra

Introduction

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

Prototype

public long getLongExtra(String name, long defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.devbrackets.android.playlistcore.service.PlaylistServiceCore.java

/**
 * Handles the intents posted by the {@link BasePlaylistManager} through
 * the <code>invoke*</code> methods.
 *///from   ww  w . ja  v  a2 s  .  c  o  m
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || intent.getAction() == null) {
        return getServiceContinuationMethod();
    }

    //This is a workaround for an issue on the Samsung Galaxy S3 (4.4.2) where the onStartCommand will occasionally get called before onCreate
    if (!onCreateCalled) {
        Log.d(TAG, "Starting Samsung workaround");
        workaroundIntent = intent;
        onCreate();
        return getServiceContinuationMethod();
    }

    if (RemoteActions.ACTION_START_SERVICE.equals(intent.getAction())) {
        seekToPosition = intent.getLongExtra(RemoteActions.ACTION_EXTRA_SEEK_POSITION, -1);
        immediatelyPause = intent.getBooleanExtra(RemoteActions.ACTION_EXTRA_START_PAUSED, false);

        startItemPlayback();
    } else {
        handleRemoteAction(intent.getAction(), intent.getExtras());
    }

    return getServiceContinuationMethod();
}

From source file:com.android.deskclock.AlarmClockFragment.java

@Override
public void onResume() {
    super.onResume();

    final DeskClock activity = (DeskClock) getActivity();
    if (activity.getSelectedTab() == DeskClock.ALARM_TAB_INDEX) {
        setFabAppearance();//from   w  w  w  .  j a v  a2  s.co m
        setLeftRightButtonAppearance();
    }
    final int startDay = Utils.getZeroIndexedFirstDayOfWeek(getActivity());
    mDayOrder = new int[DaysOfWeek.DAYS_IN_A_WEEK];

    for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; ++i) {
        mDayOrder[i] = DAY_ORDER[(startDay + i) % 7];
    }

    // Check if another app asked us to create a blank new alarm.
    final Intent intent = getActivity().getIntent();
    if (intent.hasExtra(ALARM_CREATE_NEW_INTENT_EXTRA)) {
        if (intent.getBooleanExtra(ALARM_CREATE_NEW_INTENT_EXTRA, false)) {
            // An external app asked us to create a blank alarm.
            startCreatingAlarm();
        }

        // Remove the CREATE_NEW extra now that we've processed it.
        intent.removeExtra(ALARM_CREATE_NEW_INTENT_EXTRA);
    } else if (intent.hasExtra(SCROLL_TO_ALARM_INTENT_EXTRA)) {
        long alarmId = intent.getLongExtra(SCROLL_TO_ALARM_INTENT_EXTRA, Alarm.INVALID_ID);
        if (alarmId != Alarm.INVALID_ID) {
            mScrollToAlarmId = alarmId;
            if (mCursorLoader != null && mCursorLoader.isStarted()) {
                // We need to force a reload here to make sure we have the latest view
                // of the data to scroll to.
                mCursorLoader.forceLoad();
            }
        }

        // Remove the SCROLL_TO_ALARM extra now that we've processed it.
        intent.removeExtra(SCROLL_TO_ALARM_INTENT_EXTRA);
    }

    setTimePickerListener();
}

From source file:org.kontalk.ui.ComposeMessage.java

private Bundle processIntent(Bundle savedInstanceState) {
    Intent intent;
    if (savedInstanceState != null) {
        mLostFocus = savedInstanceState.getBoolean("lostFocus");

        Uri uri = savedInstanceState.getParcelable(Uri.class.getName());
        if (uri == null) {
            Log.d(TAG, "restoring non-loaded conversation, aborting");
            finish();/*from   w  w  w . ja va  2  s .  co  m*/
            return null;
        }
        intent = new Intent(ACTION_VIEW_USERID, uri);
    } else {
        intent = getIntent();
    }

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

        // view intent
        // view conversation - just threadId provided
        // view conversation - just userId provided
        if (Intent.ACTION_VIEW.equals(action) || ACTION_VIEW_CONVERSATION.equals(action)
                || ACTION_VIEW_USERID.equals(action)) {
            Uri uri = intent.getData();

            // two-panes UI: start conversation list
            if (Kontalk.hasTwoPanesUI(this)) {
                Intent startIntent = new Intent(action, uri, getApplicationContext(),
                        ConversationsActivity.class);
                startActivity(startIntent);
                // no need to go further
                finish();
                return null;
            }
            // single-pane UI: start normally
            else {
                args = new Bundle();
                args.putString("action", action);
                args.putParcelable("data", uri);
                args.putLong(EXTRA_MESSAGE, intent.getLongExtra(EXTRA_MESSAGE, -1));
                args.putString(EXTRA_HIGHLIGHT, intent.getStringExtra(EXTRA_HIGHLIGHT));
                args.putBoolean(EXTRA_CREATING_GROUP, intent.getBooleanExtra(EXTRA_CREATING_GROUP, false));
            }
        }

        // send external content
        else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            sendIntent = intent;
            String mime = intent.getType();

            Log.i(TAG, "sending data to someone: " + mime);
            chooseContact();

            // onActivityResult will handle the rest
            return null;
        }

        // send to someone
        else if (Intent.ACTION_SENDTO.equals(action)) {
            try {
                Uri uri = intent.getData();
                // a phone number should come here...
                String number = NumberValidator.fixNumber(this, uri.getSchemeSpecificPart(),
                        Authenticator.getDefaultAccountName(this), 0);
                // compute hash and open conversation
                String jid = XMPPUtils.createLocalJID(this, MessageUtils.sha1(number));

                // two-panes UI: start conversation list
                if (Kontalk.hasTwoPanesUI(this)) {
                    Intent startIntent = new Intent(getApplicationContext(), ConversationsActivity.class);
                    startIntent.setAction(ACTION_VIEW_USERID);
                    startIntent.setData(Threads.getUri(jid));
                    startActivity(startIntent);
                    // no need to go further
                    finish();
                    return null;
                }
                // single-pane UI: start normally
                else {
                    args = new Bundle();
                    args.putString("action", ComposeMessage.ACTION_VIEW_USERID);
                    args.putParcelable("data", Threads.getUri(jid));
                    args.putString("number", number);
                }
            } catch (Exception e) {
                Log.e(TAG, "invalid intent", e);
                finish();
            }
        }

        return args;
    }

    return null;
}

From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java

protected void handleActions(Bundle savedInstanceState, Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();//  w  ww.  jav  a  2 s. co m
    Uri dataUri = intent.getData();
    String scheme = intent.getScheme();

    if (extras == null) {
        extras = new Bundle();
    }

    if (Intent.ACTION_VIEW.equals(action)) {
        // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
        // override action to delegate it to Keychain's ACTION_IMPORT_KEY
        action = ACTION_IMPORT_KEY;
    }

    if (scheme != null && scheme.toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
        /* Scanning a fingerprint directly with Barcode Scanner */
        loadFromFingerprintUri(savedInstanceState, dataUri);
    } else if (ACTION_IMPORT_KEY.equals(action)) {
        /* Keychain's own Actions */

        // display file fragment
        loadNavFragment(1, null);

        if (dataUri != null) {
            // action: directly load data
            startListFragment(savedInstanceState, null, dataUri, null);
        } else if (extras.containsKey(EXTRA_KEY_BYTES)) {
            byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES);

            // action: directly load data
            startListFragment(savedInstanceState, importData, null, null);
        }
    } else if (ACTION_IMPORT_KEY_FROM_KEYSERVER.equals(action)) {
        String query = null;
        if (extras.containsKey(EXTRA_QUERY)) {
            query = extras.getString(EXTRA_QUERY);
        } else if (extras.containsKey(EXTRA_KEY_ID)) {
            long keyId = intent.getLongExtra(EXTRA_KEY_ID, 0);
            if (keyId != 0) {
                query = PgpKeyHelper.convertKeyIdToHex(keyId);
            }
        } else if (extras.containsKey(EXTRA_FINGERPRINT)) {
            String fingerprint = intent.getStringExtra(EXTRA_FINGERPRINT);
            if (fingerprint != null) {
                query = "0x" + fingerprint;
            }
        } else {
            Log.e(Constants.TAG, "IMPORT_KEY_FROM_KEYSERVER action needs to contain the 'query', "
                    + "'key_id', or 'fingerprint' extra!");
            return;
        }

        // display keyserver fragment with query
        Bundle args = new Bundle();
        args.putString(ImportKeysServerFragment.ARG_QUERY, query);
        loadNavFragment(0, args);

        // action: search immediately
        startListFragment(savedInstanceState, null, null, query);
    } else if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(1, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
        // also exposed in AndroidManifest

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(2, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {

        // NOTE: this only displays the appropriate fragment, no actions are taken
        loadNavFragment(3, null);

        // no immediate actions!
        startListFragment(savedInstanceState, null, null, null);
    } else {
        startListFragment(savedInstanceState, null, null, null);
    }
}

From source file:info.snowhow.plugin.RecorderService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(LOG_TAG, "Received start id " + startId + ": " + intent);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        showNoGPSAlert();/* w w w .j  a va2  s. com*/
    }
    runningID = startId;
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.

    if (intent == null) {
        tf = sharedPref.getString("runningTrackFile", "");
        Log.w(LOG_TAG, "Intent is null, trying to continue to write to file " + tf + " lm " + locationManager);
        minimumPrecision = sharedPref.getFloat("runningPrecision", 0);
        distanceChange = sharedPref.getLong("runningDistanceChange", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES);
        updateTime = sharedPref.getLong("runningUpdateTime", MINIMUM_TIME_BETWEEN_UPDATES);
        updateTimeFast = sharedPref.getLong("runningUpdateTimeFast", MINIMUM_TIME_BETWEEN_UPDATES_FAST);
        speedLimit = sharedPref.getLong("runningSpeedLimit", SPEED_LIMIT);
        adaptiveRecording = sharedPref.getBoolean("adaptiveRecording", false);
        int count = sharedPref.getInt("count", 0);
        if (count > 0) {
            firstPoint = false;
        }
        if (tf == null || tf == "") {
            Log.e(LOG_TAG, "No trackfile found ... exit clean here");
            cleanUp();
            return START_NOT_STICKY;
        }
    } else {
        tf = intent.getStringExtra("fileName");
        Log.d(LOG_TAG, "FILENAME for recording is " + tf);
        minimumPrecision = intent.getFloatExtra("precision", 0);
        distanceChange = intent.getLongExtra("distance_change", MINIMUM_DISTANCE_CHANGE_FOR_UPDATES);
        updateTime = intent.getLongExtra("update_time", MINIMUM_TIME_BETWEEN_UPDATES);
        updateTimeFast = intent.getLongExtra("update_time_fast", MINIMUM_TIME_BETWEEN_UPDATES_FAST);
        speedLimit = intent.getLongExtra("speed_limit", SPEED_LIMIT);
        adaptiveRecording = intent.getBooleanExtra("adaptiveRecording", false);
        editor.putString("runningTrackFile", tf);
        editor.putFloat("runningPrecision", minimumPrecision);
        editor.putLong("runningDistanceChange", distanceChange);
        editor.putLong("runningUpdateTime", updateTime);
        editor.putLong("runningUpdateTimeFast", updateTimeFast);
        editor.putLong("runningSpeedLimit", speedLimit);
        editor.putBoolean("adaptiveRecording", adaptiveRecording);
        editor.commit();
    }

    Intent cordovaMainIntent;
    try {
        PackageManager packageManager = this.getPackageManager();
        cordovaMainIntent = packageManager.getLaunchIntentForPackage(this.getPackageName());
        Log.d(LOG_TAG, "got cordovaMainIntent " + cordovaMainIntent);
        if (cordovaMainIntent == null) {
            throw new PackageManager.NameNotFoundException();
        }
    } catch (PackageManager.NameNotFoundException e) {
        cordovaMainIntent = new Intent();
    }
    PendingIntent pend = PendingIntent.getActivity(this, 0, cordovaMainIntent, 0);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ifString), 0);
    NotificationCompat.Action stop = new NotificationCompat.Action.Builder(android.R.drawable.ic_delete,
            "Stop recording", pendingIntent).build();
    note = new NotificationCompat.Builder(this).setContentTitle(applicationName + " GPS tracking")
            .setSmallIcon(android.R.drawable.ic_menu_mylocation).setOngoing(true).setContentIntent(pend)
            .setContentText("No location yet.");
    note.addAction(stop);

    nm = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE);
    nm.notify(0, note.build());

    recording = true;
    Log.d(LOG_TAG, "recording in handleIntent");
    try { // create directory first, if it does not exist
        File trackFile = new File(tf).getParentFile();
        if (!trackFile.exists()) {
            trackFile.mkdirs();
            Log.d(LOG_TAG, "done creating path for trackfile: " + trackFile);
        }
        Log.d(LOG_TAG, "going to create RandomAccessFile " + tf);
        myWriter = new RandomAccessFile(tf, "rw");
        if (intent != null) { // start new file
            // myWriter.setLength(0);    // delete all contents from file
            String trackName = intent.getStringExtra("trackName");
            String trackHead = initTrack(trackName).toString();
            myWriter.write(trackHead.getBytes());
            // we want to write JSON manually for streamed writing
            myWriter.seek(myWriter.length() - 1);
            myWriter.write(",\"coordinates\":[]}".getBytes());
        }
    } catch (IOException e) {
        Log.d(LOG_TAG, "io error. cannot write to file " + tf);
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, distanceChange, mgpsll);
    if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, updateTime, distanceChange,
                mnetll);
    }
    return START_STICKY;
}

From source file:org.jitsi.android.gui.DialogActivity.java

/**
 * {@inheritDoc}//w ww .ja va2 s  . co  m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();

    setContentView(R.layout.alert_dialog);
    View content = findViewById(android.R.id.content);

    // Title
    setTitle(intent.getStringExtra(EXTRA_TITLE));

    // Message or custom content
    String contentFragment = intent.getStringExtra(EXTRA_CONTENT_FRAGMENT);
    if (contentFragment != null) {
        // Hide alert text
        ViewUtil.ensureVisible(content, R.id.alertText, false);

        // Display content fragment
        if (savedInstanceState == null) {
            try {
                // Instantiate content fragment
                Class contentClass = Class.forName(contentFragment);
                Fragment fragment = (Fragment) contentClass.newInstance();

                // Set fragment arguments
                fragment.setArguments(intent.getBundleExtra(EXTRA_CONTENT_ARGS));

                // Insert the fragment
                getSupportFragmentManager().beginTransaction().replace(R.id.alertContent, fragment).commit();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } else {
        ViewUtil.setTextViewValue(findViewById(android.R.id.content), R.id.alertText,
                intent.getStringExtra(EXTRA_MESSAGE));
    }

    // Confirm button text
    String confirmTxt = intent.getStringExtra(EXTRA_CONFRIM_TXT);
    if (confirmTxt != null) {
        ViewUtil.setTextViewValue(content, R.id.okButton, confirmTxt);
    }

    // Show cancel button if confirm label is not null
    ViewUtil.ensureVisible(content, R.id.cancelButton, confirmTxt != null);

    // Sets the listener
    this.listenerID = intent.getLongExtra(EXTRA_LISTENER_ID, -1);
    if (listenerID != -1) {
        this.listener = listenersMap.get(listenerID);
    }

    this.cancelable = intent.getBooleanExtra(EXTRA_CANCELABLE, true);

    // Prevents from closing the dialog on outside touch
    setFinishOnTouchOutside(cancelable);

    // Removes the buttons
    if (intent.getBooleanExtra(EXTRA_REMOVE_BUTTONS, false)) {
        ViewUtil.ensureVisible(content, R.id.okButton, false);
        ViewUtil.ensureVisible(content, R.id.cancelButton, false);
    }

    // Close this dialog on ACTION_CLOSE_DIALOG broadcast
    long dialogId = intent.getLongExtra(EXTRA_DIALOG_ID, -1);
    if (dialogId != -1) {
        this.closeIntentListener = new CloseDialogListener(dialogId);
        registerReceiver(closeIntentListener, new IntentFilter(ACTION_CLOSE_DIALOG));

        // Adds this dialog to active dialogs list and notifies all waiting
        // threads.
        synchronized (displayedDialogs) {
            displayedDialogs.add(dialogId);
            displayedDialogs.notifyAll();
        }
    }
}

From source file:com.csipsimple.ui.incall.CallActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case PICKUP_SIP_URI_XFER:
        if (resultCode == RESULT_OK && service != null) {
            String callee = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            int callId = data.getIntExtra(CALL_ID, -1);
            if (callId != -1) {
                try {
                    service.xfer((int) callId, callee);
                } catch (RemoteException e) {
                    // TODO : toaster
                }//from www  .j  a va2  s.  com
            }
        }
        return;
    case PICKUP_SIP_URI_NEW_CALL:
        if (resultCode == RESULT_OK && service != null) {
            Log.d(TAG, "OnActivityResult, PICKUP_SIP_URI_NEW_CALL");
            String callee = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            long accountId = data.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID);
            if (accountId != SipProfile.INVALID_ID) {
                try {
                    service.makeCall(callee, (int) accountId);
                } catch (RemoteException e) {
                    // TODO : toaster
                }
            }
        }
        return;
    default:
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.owncloud.android.services.OperationsService.java

/**
 * Creates a new operation, as described by operationIntent.
 * //from  ww  w  . ja v a  2  s . c om
 * TODO - move to ServiceHandler (probably)
 * 
 * @param operationIntent       Intent describing a new operation to queue and execute.
 * @return                      Pair with the new operation object and the information about its
 *                              target server.
 */
private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
    RemoteOperation operation = null;
    Target target = null;
    try {
        if (!operationIntent.hasExtra(EXTRA_ACCOUNT) && !operationIntent.hasExtra(EXTRA_SERVER_URL)) {
            Log_OC.e(TAG, "Not enough information provided in intent");

        } else {
            Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
            String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
            String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
            target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl), cookie);

            String action = operationIntent.getAction();
            if (action.equals(ACTION_CREATE_SHARE_VIA_LINK)) { // Create public share via link

                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);

                if (remotePath != null && remotePath.length() > 0) {

                    operation = new CreateShareViaLinkOperation(remotePath);

                    String name = operationIntent.getStringExtra(EXTRA_SHARE_NAME);
                    ((CreateShareViaLinkOperation) operation).setName(name);

                    String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                    ((CreateShareViaLinkOperation) operation).setPassword(password);

                    long expirationDateMillis = operationIntent
                            .getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);

                    ((CreateShareViaLinkOperation) operation).setExpirationDateInMillis(expirationDateMillis);

                    Boolean uploadToFolderPermission = operationIntent
                            .getBooleanExtra(EXTRA_SHARE_PUBLIC_UPLOAD, false);

                    ((CreateShareViaLinkOperation) operation).setPublicUpload(uploadToFolderPermission);

                    int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS,
                            OCShare.DEFAULT_PERMISSION);

                    ((CreateShareViaLinkOperation) operation).setPermissions(permissions);
                }

            } else if (ACTION_UPDATE_SHARE_VIA_LINK.equals(action)) {
                long shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                operation = new UpdateShareViaLinkOperation(shareId);

                String name = operationIntent.getStringExtra(EXTRA_SHARE_NAME);
                ((UpdateShareViaLinkOperation) operation).setName(name);

                String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
                ((UpdateShareViaLinkOperation) operation).setPassword(password);

                long expirationDate = operationIntent.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0);
                ((UpdateShareViaLinkOperation) operation).setExpirationDate(expirationDate);

                if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
                    ((UpdateShareViaLinkOperation) operation)
                            .setPublicUpload(operationIntent.getBooleanExtra(EXTRA_SHARE_PUBLIC_UPLOAD, false));
                }

                if (operationIntent.hasExtra(EXTRA_SHARE_PERMISSIONS)) {
                    ((UpdateShareViaLinkOperation) operation).setPermissions(
                            operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, OCShare.DEFAULT_PERMISSION));
                }

            } else if (ACTION_UPDATE_SHARE_WITH_SHAREE.equals(action)) {
                // Update private share, only permissions
                long shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                operation = new UpdateSharePermissionsOperation(shareId);
                int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, 1);
                ((UpdateSharePermissionsOperation) operation).setPermissions(permissions);

            } else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) {
                // Create private share with user or group
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
                ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
                int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
                if (remotePath.length() > 0) {
                    operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType,
                            permissions);
                }

            } else if (action.equals(ACTION_UNSHARE)) { // Unshare file
                long shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
                operation = new RemoveShareOperation(shareId);

            } else if (action.equals(ACTION_GET_SERVER_INFO)) {
                // check OC server and get basic information from it
                operation = new GetServerInfoOperation(serverUrl, OperationsService.this);

            } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
                // CREATE ACCESS TOKEN to the OAuth server
                String code = operationIntent.getStringExtra(EXTRA_OAUTH2_AUTHORIZATION_CODE);

                OAuth2Provider oAuth2Provider = OAuth2ProvidersRegistry.getInstance().getProvider();
                OAuth2RequestBuilder builder = oAuth2Provider.getOperationBuilder();
                builder.setGrantType(OAuth2GrantType.AUTHORIZATION_CODE);
                builder.setRequest(OAuth2RequestBuilder.OAuthRequest.CREATE_ACCESS_TOKEN);
                builder.setAuthorizationCode(code);

                operation = builder.buildOperation();

            } else if (action.equals(ACTION_GET_USER_NAME)) {
                // Get User Name
                operation = new GetRemoteUserInfoOperation();

            } else if (action.equals(ACTION_RENAME)) {
                // Rename file or folder
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                String newName = operationIntent.getStringExtra(EXTRA_NEWNAME);
                operation = new RenameFileOperation(remotePath, newName);

            } else if (action.equals(ACTION_REMOVE)) {
                // Remove file or folder
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                boolean onlyLocalCopy = operationIntent.getBooleanExtra(EXTRA_REMOVE_ONLY_LOCAL, false);
                operation = new RemoveFileOperation(remotePath, onlyLocalCopy);

            } else if (action.equals(ACTION_CREATE_FOLDER)) {
                // Create Folder
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                boolean createFullPath = operationIntent.getBooleanExtra(EXTRA_CREATE_FULL_PATH, true);
                operation = new CreateFolderOperation(remotePath, createFullPath);

            } else if (action.equals(ACTION_SYNC_FILE)) {
                // Sync file
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                operation = new SynchronizeFileOperation(remotePath, account, getApplicationContext());

            } else if (action.equals(ACTION_SYNC_FOLDER)) {
                // Sync folder (all its descendant files are sync'ed)
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                boolean pushOnly = operationIntent.getBooleanExtra(EXTRA_PUSH_ONLY, false);
                boolean syncContentOfRegularFiles = operationIntent.getBooleanExtra(EXTRA_SYNC_REGULAR_FILES,
                        false);
                operation = new SynchronizeFolderOperation(this, // TODO remove this dependency from construction time
                        remotePath, account, System.currentTimeMillis(), // TODO remove this dependency from construction time
                        pushOnly, false, syncContentOfRegularFiles);

            } else if (action.equals(ACTION_MOVE_FILE)) {
                // Move file/folder
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                operation = new MoveFileOperation(remotePath, newParentPath);

            } else if (action.equals(ACTION_COPY_FILE)) {
                // Copy file/folder
                String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
                String newParentPath = operationIntent.getStringExtra(EXTRA_NEW_PARENT_PATH);
                operation = new CopyFileOperation(remotePath, newParentPath, account);

            } else if (action.equals(ACTION_CHECK_CURRENT_CREDENTIALS)) {
                // Check validity of currently stored credentials for a given account
                operation = new CheckCurrentCredentialsOperation(account);

            }
        }

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Bad information provided in intent: " + e.getMessage());
        operation = null;
    }

    if (operation != null) {
        return new Pair<>(target, operation);
    } else {
        return null;
    }
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (requestCode == SELECT_CATEGORY_REQUEST && intent != null) {
        mCatId = intent.getLongExtra("cat_id", 0);
        mLabel = intent.getStringExtra("label");
        mCategoryButton.setText(mLabel);
        setDirty(true);//from   ww  w. j  a  v  a  2  s.  c  o m
    }
    if (requestCode == PICTURE_REQUEST_CODE && resultCode == RESULT_OK) {
        Uri uri;
        String errorMsg;
        if (intent == null) {
            uri = mPictureUriTemp;
            Log.d(MyApplication.TAG,
                    "got result for PICTURE request, intent null, relying on stored output uri :"
                            + mPictureUriTemp);
        } else if (intent.getData() != null) {
            uri = intent.getData();
            Log.d(MyApplication.TAG,
                    "got result for PICTURE request, found uri in intent data :" + uri.toString());
        } else {
            Log.d(MyApplication.TAG,
                    "got result for PICTURE request, intent != null, getData() null, relying on stored output uri :"
                            + mPictureUriTemp);
            uri = mPictureUriTemp;
        }
        if (uri != null) {
            if (isFileAndNotExists(uri)) {
                errorMsg = "Error while retrieving image: File not found: " + uri;
            } else {
                mPictureUri = uri;
                setPicture();
                setDirty(true);
                return;
            }
        } else {
            errorMsg = "Error while retrieving image: No data found.";
        }
        AcraHelper.report(new Exception(errorMsg));
        Toast.makeText(this, errorMsg, Toast.LENGTH_LONG).show();
    }
}