Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.money.manager.ex.settings.PerDatabaseFragment.java

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

    switch (requestCode) {
    case REQUEST_PICK_CURRENCY:
        // Returning from the currency picker screen.
        if ((resultCode == Activity.RESULT_OK) && (data != null)) {
            int currencyId = data.getIntExtra(CurrencyListActivity.INTENT_RESULT_CURRENCYID, -1);
            // set preference
            CurrencyService utils = new CurrencyService(getActivity());
            utils.setBaseCurrencyId(currencyId);
            // refresh the displayed value.
            showCurrentDefaultCurrency();

            // notify the user to update exchange rates!
            showCurrencyChangeNotification();
        }//from w  ww.  ja  va 2s.co m
        break;
    }
}

From source file:com.awt.supark.ParkingTimerService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    Log.i("Service", "---------- Service started ----------");

    loadDatabase();//from w w  w  .j  av a  2 s .  co m

    // Very lame method to check if there's any extras attached - but it works.
    try {
        int startNewId = intent.getIntExtra("startId", 0);
        if (startNewId > 0) {
            requestCars();
        }
    } catch (Exception e) {
        Log.i("Service", "No new startId - the service is in refreshing mode");
    }

    // Checking that are there any cars in the database. If the result is true starts the timer, otherwise destroys the service.
    if (isThereAnyCars()) {
        startTimer(TIMER_PERIOD);
    } else {
        this.stopService(intent);
    }

    return START_STICKY;
}

From source file:com.appfirst.activities.details.AFServerDetail.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.server);// ww  w . j  av a 2  s .  co m
    Intent i = getIntent();
    int selected = i.getIntExtra(AFServerDetail.class.getName() + ".selected", -1);
    if (selected < 0) {
        Log.e(TAG, "Unlikely, nothing selected");
        return;
    }
    updateViewWithSelected(selected);
    setDialogMaxInnerSpace();
    setupGraphOptions();

}

From source file:com.achep.base.ui.activities.SettingsActivity.java

private void setTitleFromIntent(Intent intent) {
    final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
    if (initialTitleResId > 0) {
        mInitialTitle = null;/*from w  ww. j a  va  2s .c om*/
        mInitialTitleResId = initialTitleResId;
        setTitle(mInitialTitleResId);
    } else {
        mInitialTitleResId = -1;
        final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
        mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
        setTitle(mInitialTitle);
    }
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferService.java

/**
 * Executes command received by the service.
 *
 * @param intent received intent/*  w w w  . j a  va2  s .  co  m*/
 */
void execCommand(Intent intent) {
    // update last active time
    lastActiveTime = System.currentTimeMillis();

    final String action = intent.getAction();
    final int id = intent.getIntExtra(INTENT_BUNDLE_TRANSFER_ID, 0);

    if (id == 0) {
        LOGGER.error("Invalid id: " + id);
        return;
    }

    if (INTENT_ACTION_TRANSFER_ADD.equals(action)) {
        if (updater.getTransfer(id) != null) {
            LOGGER.warn("Transfer has already been added: " + id);
        } else {
            /*
             * only add transfer when network is available or else relies on
             * the network change listener to scan the database
             */
            final TransferRecord transfer = dbUtil.getTransferById(id);
            if (transfer != null) {
                updater.addTransfer(transfer);
                transfer.start(s3, dbUtil, updater, networkInfoReceiver);
            } else {
                LOGGER.error("Can't find transfer: " + id);
            }
        }
    } else if (INTENT_ACTION_TRANSFER_PAUSE.equals(action)) {
        TransferRecord transfer = updater.getTransfer(id);
        if (transfer == null) {
            transfer = dbUtil.getTransferById(id);
        }
        if (transfer != null) {
            transfer.pause(s3, updater);
        }
    } else if (INTENT_ACTION_TRANSFER_RESUME.equals(action)) {
        TransferRecord transfer = updater.getTransfer(id);
        if (transfer == null) {
            transfer = dbUtil.getTransferById(id);
            if (transfer != null) {
                updater.addTransfer(transfer);
            } else {
                LOGGER.error("Can't find transfer: " + id);
            }
        }
        if (transfer != null) {
            transfer.start(s3, dbUtil, updater, networkInfoReceiver);
        }
    } else if (INTENT_ACTION_TRANSFER_CANCEL.equals(action)) {
        TransferRecord transfer = updater.getTransfer(id);
        if (transfer == null) {
            transfer = dbUtil.getTransferById(id);
        }
        if (transfer != null) {
            transfer.cancel(s3, updater);
        }
    } else {
        LOGGER.error("Unknown action: " + action);
    }
}

From source file:com.android.calendar.alerts.DismissAlarmsService.java

@Override
public void onHandleIntent(Intent intent) {

    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    long[] eventStarts = intent.getLongArrayExtra(AlertUtils.EVENT_STARTS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();

    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;/* w  w w  .  ja  va  2  s .c om*/

    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        alarmIds.add(new AlarmId(eventId, eventStart));
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID
                + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0 && eventStarts != null
            && eventIds.length == eventStarts.length) {
        selection = buildMultipleEventsQuery(eventIds);
        for (int i = 0; i < eventIds.length; i++) {
            alarmIds.add(new AlarmId(eventIds[i], eventStarts[i]));
        }
    } else {
        // NOTE: I don't believe that this ever happens.
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }

    GlobalDismissManager.dismissGlobally(getApplicationContext(), alarmIds);

    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);

    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }

    if (showEvent) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);

        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i)
                .startActivities();
    }
}

From source file:com.brq.wallet.activity.ScanActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (Activity.RESULT_CANCELED == resultCode) {
        finishError(R.string.cancelled, "");
        return;/*from  w  ww  .  j a  va2s.c  om*/
    }

    //since it was not the handler, it can only be the scanner
    Preconditions.checkState(SCANNER_RESULT_CODE == requestCode);

    // If the last autofocus setting got saved in an extra-field, change the app settings accordingly
    int autoFocus = intent.getIntExtra("ENABLE_CONTINUOUS_FOCUS", -1);
    if (autoFocus != -1) {
        MbwManager.getInstance(this).setContinuousFocus(autoFocus == 1);
    }

    if (!isQRCode(intent)) {
        finishError(R.string.unrecognized_format, "");
        return;
    }

    String content = intent.getStringExtra("SCAN_RESULT").trim();
    // Get rid of any UTF-8 BOM marker. Those should not be present, but might have slipped in nonetheless,
    if (content.length() != 0 && content.charAt(0) == '\uFEFF')
        content = content.substring(1);

    // Call the stringHandler activity and pass its result to our caller
    Intent handlerIntent = StringHandlerActivity.getIntent(this, _stringHandleConfig, content);
    handlerIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    this.startActivity(handlerIntent);

    // we are done here...
    this.finish();
}

From source file:com.brewcrewfoo.performance.fragments.MemSettings.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    getActivity();/*w ww. ja  va  2s  .  co m*/
    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            final int r = data.getIntExtra("result", 0);
            Log.d(TAG, "input = " + r);
            switch (r) {
            case 1:
                //    mKSMsettings.setSummary(getString(R.string.ksm_pagtoscan)+" "+Helpers.readOneLine(KSM_PAGESTOSCAN_PATH[ksm])+" | "+getString(R.string.ksm_sleep)+" "+Helpers.readOneLine(KSM_SLEEP_PATH[ksm]));
                break;
            case 2:
                curdisk = mPreferences.getInt(PREF_ZRAM, Math.round(maxdisk * 18 / 100));
                final int percent = Math.round(curdisk * 100 / maxdisk);
                mZRAMsettings.setSummary(getString(R.string.ps_zram) + " | "
                        + getString(R.string.zram_disk_size, Helpers.ReadableByteCount(curdisk * 1024 * 1024))
                        + " (" + String.valueOf(percent) + "%)");
                break;
            }
        }
        //if (resultCode == Activity.RESULT_CANCELED) {}
    }
}

From source file:com.bydavy.card.receipts.activities.ReceiptListActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Result from ReceiptPagerActivity (last index browsed by the user)
    if ((requestCode == REQUEST_CODE_RECEIPT_PAGER) && (resultCode == Activity.RESULT_OK)) {
        final int index = data.getIntExtra(ReceiptPagerActivity.RESULT_INDEX, 0);
        // Fragments loading complete
        if ((mReceiptListFragment.getState() == StateFragmentListener.STATE_COMPLETED) && ((!mDualPane)
                || (mDualPane && (mPagerFragment.getState() == StateFragmentListener.STATE_COMPLETED)))) {
            setIndex(index);//from  w w  w .  ja  v  a 2s .  c  o  m
        } else {
            // TODO find a better way to achieve this
            mOnCompleteRunnable.add(new Runnable() {
                @Override
                public void run() {
                    setIndex(index);
                }
            });
        }
    }
}

From source file:com.envyserve.githubreference.billing.BillingProcessor.java

public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != PURCHASE_FLOW_REQUEST_CODE)
        return false;
    if (data == null) {
        Log.e(LOG_TAG, "handleActivityResult: data is null!");
        return false;
    }/*from w  w  w. j a v  a 2  s  .  co  m*/
    int responseCode = data.getIntExtra(Constants.RESPONSE_CODE, Constants.BILLING_RESPONSE_RESULT_OK);
    Log.d(LOG_TAG, String.format("resultCode = %d, responseCode = %d", resultCode, responseCode));
    String purchasePayload = getPurchasePayload();
    if (resultCode == Activity.RESULT_OK && responseCode == Constants.BILLING_RESPONSE_RESULT_OK
            && !TextUtils.isEmpty(purchasePayload)) {
        String purchaseData = data.getStringExtra(Constants.INAPP_PURCHASE_DATA);
        String dataSignature = data.getStringExtra(Constants.RESPONSE_INAPP_SIGNATURE);
        try {
            JSONObject purchase = new JSONObject(purchaseData);
            String productId = purchase.getString(Constants.RESPONSE_PRODUCT_ID);
            String developerPayload = purchase.getString(Constants.RESPONSE_PAYLOAD);
            if (developerPayload == null)
                developerPayload = "";
            boolean purchasedSubscription = purchasePayload.startsWith(Constants.PRODUCT_TYPE_SUBSCRIPTION);
            if (purchasePayload.equals(developerPayload)) {
                if (verifyPurchaseSignature(productId, purchaseData, dataSignature)) {
                    BillingCache cache = purchasedSubscription ? cachedSubscriptions : cachedProducts;
                    cache.put(productId, purchaseData, dataSignature);
                    if (eventHandler != null)
                        eventHandler.onProductPurchased(productId,
                                new TransactionDetails(new PurchaseInfo(purchaseData, dataSignature)));
                } else {
                    Log.e(LOG_TAG, "Public key signature doesn't match!");
                    if (eventHandler != null)
                        eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
                }
            } else {
                Log.e(LOG_TAG, String.format("Payload mismatch: %s != %s", purchasePayload, developerPayload));
                if (eventHandler != null)
                    eventHandler.onBillingError(Constants.BILLING_ERROR_INVALID_SIGNATURE, null);
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
            if (eventHandler != null)
                eventHandler.onBillingError(Constants.BILLING_ERROR_OTHER_ERROR, null);
        }
    } else {
        if (eventHandler != null)
            eventHandler.onBillingError(responseCode, null);
    }
    return true;
}