Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:com.battlelancer.seriesguide.api.SeriesGuideExtension.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;/*  www .j av a2  s.c o m*/
    }

    String action = intent.getAction();
    if (ACTION_SUBSCRIBE.equals(action)) {
        // just subscribing or unsubscribing
        handleSubscribe((ComponentName) intent.getParcelableExtra(EXTRA_SUBSCRIBER_COMPONENT),
                intent.getStringExtra(EXTRA_TOKEN));
    } else if (ACTION_UPDATE.equals(action)) {
        // subscriber requests an updated action
        if (intent.hasExtra(EXTRA_ENTITY_IDENTIFIER) && intent.hasExtra(EXTRA_EPISODE)) {
            handleEpisodeRequest(intent.getIntExtra(EXTRA_ENTITY_IDENTIFIER, 0),
                    intent.getBundleExtra(EXTRA_EPISODE));
        }
    }
}

From source file:com.dsi.ant.antplus.pluginsampler.weightscale.Activity_WeightScaleSampler.java

/**
 * Resets the PCC connection to request access again and clears any existing display data.
 *//*from   ww w .  j  a  va 2s .c  o m*/
private void resetPcc() {
    //Release the old access if it exists
    if (releaseHandle != null) {
        releaseHandle.close();
    }

    //Reset the text display
    tv_status.setText("Connecting...");

    setRequestButtonsEnabled(false);
    resetWeightRequestedDataDisplay("---");
    tv_bodyWeightBroadcast.setText("---");

    tv_estTimestamp.setText("---");

    tv_hardwareRevision.setText("---");
    tv_manufacturerID.setText("---");
    tv_modelNumber.setText("---");

    tv_mainSoftwareRevision.setText("---");
    tv_supplementalSoftwareRevision.setText("");
    tv_serialNumber.setText("---");

    Intent intent = getIntent();
    if (intent.hasExtra(Activity_MultiDeviceSearchSampler.EXTRA_KEY_MULTIDEVICE_SEARCH_RESULT)) {
        // device has already been selected through the multi-device search
        MultiDeviceSearchResult result = intent
                .getParcelableExtra(Activity_MultiDeviceSearchSampler.EXTRA_KEY_MULTIDEVICE_SEARCH_RESULT);
        releaseHandle = AntPlusWeightScalePcc.requestAccess(this, result.getAntDeviceNumber(), 0,
                mResultReceiver, mDeviceStateChangeReceiver);
    } else {
        // starts the plugins UI search
        releaseHandle = AntPlusWeightScalePcc.requestAccess(this, this, mResultReceiver,
                mDeviceStateChangeReceiver);
    }
}

From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;/*w  w  w  . j  a  va  2s .  co m*/
            notificationAccumulatedAmount = Coin.ZERO;
            notificationAddresses.clear();

            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(
                    intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}

From source file:com.equinox.prodriver.Activities.RegisterDriverActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent != null && intent.hasExtra(SOURCE) && intent.getIntExtra(SOURCE, 0) == REQUEST_DRIVER_LICENSE) {
        licenseImage.setImageBitmap(photo1);
        licenseImageLoaded.setVisibility(View.GONE);
        photo1 = null;/* w w w  .j av  a2 s.c om*/
        editDriver.setLicenseNumber(intent.getStringExtra("id"));
        licenseValueNumber.setText(getString(R.string.id_number_text) + ": " + editDriver.getLicenseNumber());
        Calendar calendar = Calendar.getInstance();
        try {
            String expDate = intent.getStringExtra(getString(R.string.id_expiry_text));
            calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(expDate.substring(0, 2)));
            calendar.set(Calendar.MONTH, Integer.valueOf(expDate.substring(3, 5)) - 1);
            calendar.set(Calendar.YEAR, Integer.valueOf(expDate.substring(6, 10)));
            editDriver.setLicenseExpiry(calendar.getTimeInMillis());
            setIndicator(context, licenseIndicator, true);
            licenseValueExpiry.setText(getString(R.string.id_expiry_text) + ": "
                    + StringManipulation.getFormattedDate(editDriver.getLicenseExpiry()));
        } catch (NumberFormatException e) {
            setIndicator(context, licenseIndicator, false);
        }
        if (intent.hasExtra(getString(R.string.driver_dob_text)))
            try {
                String dobDate = intent.getStringExtra(getString(R.string.driver_dob_text));
                calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(dobDate.substring(0, 2)));
                calendar.set(Calendar.MONTH, Integer.valueOf(dobDate.substring(3, 5)) - 1);
                calendar.set(Calendar.YEAR, Integer.valueOf(dobDate.substring(6, 10)));
                editDriver.setDob(calendar.getTimeInMillis());
                dobValue.setText(StringManipulation.getFormattedDate(editDriver.getDob()));
            } catch (NumberFormatException ignored) {
            }
        mainScrollView.postDelayed(new Runnable() {
            @Override
            public void run() {
                mainScrollView.smoothScrollTo(0, residenceInfoLayout.getTop());
            }
        }, 1000);
    } else if (intent != null && intent.hasExtra(SOURCE)
            && intent.getIntExtra(SOURCE, 0) == REQUEST_RESIDENCE_ID) {
        editDriver.setResidenceNumber(intent.getStringExtra("id"));
        setIndicator(context, residenceIndicator, true);
        residenceValueNumber
                .setText(getString(R.string.id_number_text) + ": " + editDriver.getResidenceNumber());
        residenceImage.setImageBitmap(photo1);
        residenceImageLoaded.setVisibility(View.GONE);
        photo1 = null;
        residenceValueLegalName.setText(
                getString(R.string.legal_name) + ": " + intent.getStringExtra(getString(R.string.legal_name)));
        nationalityLayout.performClick();
    }
    if (intent != null && intent.hasExtra("VEHICLE_REG")) {
        String vehicleId = intent.getStringExtra("VEHICLE_REG");
        DriverTask driverTask = new DriverTask(vehicleFetcher, "en");
        driverTask.getVehicle.execute(vehicleId);
    }
}

From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_video_list);

    Intent intent = getIntent();
    topicId = savedInstanceState != null && savedInstanceState.containsKey(PARAM_TOPIC_ID)
            ? savedInstanceState.getString(PARAM_TOPIC_ID)
            : intent != null && intent.hasExtra(PARAM_TOPIC_ID) ? intent.getStringExtra(PARAM_TOPIC_ID) : null;

    isShowingDownloadedVideosOnly = savedInstanceState != null
            && savedInstanceState.containsKey(PARAM_SHOW_DL_ONLY)
                    ? savedInstanceState.getBoolean(PARAM_SHOW_DL_ONLY)
                    : intent != null && intent.hasExtra(PARAM_SHOW_DL_ONLY)
                            ? intent.getBooleanExtra(PARAM_SHOW_DL_ONLY, false)
                            : false;/*from   w w  w. ja  v  a  2 s  .co  m*/
}

From source file:com.blu3f1re.reddwallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    log.info("service start command: " + intent
            + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                    ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                    : ""));

    final String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;/*from  w w  w. j  a v a  2  s  . c  o  m*/
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    }

    return START_NOT_STICKY;
}

From source file:com.flowzr.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.main);// w w w  . j a v a 2 s.co  m

    actionBar = getSupportActionBar();

    //@see: http://stackoverflow.com/questions/16539251/get-rid-of-blue-line, 
    //only way found to remove on various devices 2.3x, 3.0, ...
    actionBar.setBackgroundDrawable(new ColorDrawable(R.color.f_dark));

    setupDrawer();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // create new tabs and and set up the titles of the tabs
    mAccountTab = setupAccountsTab(actionBar);
    mBlotterTab = setupBlotterTab(actionBar);
    mBudgetsTab = setupBudgetsTab(actionBar);

    Intent intent = getIntent();

    mAdapter = new MyAdapter(getSupportFragmentManager(), intent);
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    viewPager.setAdapter(mAdapter);
    viewPager.setOnPageChangeListener(this);

    mAccountTab.setTabListener(this);
    mBlotterTab.setTabListener(this);
    mBudgetsTab.setTabListener(this);

    addMyTabs();

    if (intent.hasExtra(REQUEST_BLOTTER)) {
        blotterFragment = new BlotterFragment();
        if (intent.hasExtra(EntityListActivity.REQUEST_NEW_TRANSACTION_FROM_TEMPLATE)) {
            Bundle bundle = new Bundle();
            bundle.putInt(BlotterFragment.EXTRA_REQUEST_TYPE,
                    BlotterFragment.NEW_TRANSACTION_FROM_TEMPLATE_REQUEST);
            blotterFragment.setArguments(bundle);
        }
        loadTabFragment(blotterFragment, R.layout.blotter, intent.getExtras(), TAB_BLOTTER);

    } else if (intent.hasExtra(REQUEST_SPLIT_BLOTTER)) {
        loadTabFragment(new SplitsBlotterActivity(), R.layout.blotter, intent.getExtras(), TAB_BLOTTER);
    } else if (intent.hasExtra(REQUEST_BUDGET_BLOTTER)) {
        loadTabFragment(new BudgetBlotterFragment(), R.layout.blotter, intent.getExtras(), TAB_BLOTTER);
    } else {
        StartupScreen startupScreen = MyPreferences.getStartupScreen(this);
        viewPager.setCurrentItem(startupScreen.ordinal());
    }

    if (WebViewDialog.checkVersionAndShowWhatsNewIfNeeded(this)) {
        if (mDrawerLayout != null) {
            mDrawerLayout.openDrawer(Gravity.LEFT);
        }
    }

    initialLoad();

    FlowzrSyncEngine.setUpdatable(this);
}

From source file:com.cannabiscoin.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    log.info("service start command: " + intent
            + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                    ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                    : ""));

    final String action = intent.getAction();

    if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
        notificationCount = 0;/*from  w  w  w.j av a 2s  .  c om*/
        notificationAccumulatedAmount = BigInteger.ZERO;
        notificationAddresses.clear();

        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
        log.info("will remove blockchain on service shutdown");

        resetBlockchainOnShutdown = true;
        //WalletApplication.scheduleStartBlockchainService(this);  //disconnect feature
        stopSelf();
    } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
        final Sha256Hash hash = new Sha256Hash(
                intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
        final Transaction tx = application.getWallet().getTransaction(hash);

        if (peerGroup != null) {
            log.info("broadcasting transaction " + tx.getHashAsString());
            peerGroup.broadcastTransaction(tx);
        } else {
            log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
        }
    } else if (BlockchainService.ACTION_STOP_SERVICE.equals(action)) {
        log.info("stopping self");
        // deliberate stop command, so don't schedule restart
        stopSelf();
    }

    return START_NOT_STICKY;
}

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

/**
 * Entry point to add one or several files to the queue of uploads.
 * //  w  w  w.  j  a  v a2s  .  c  o  m
 * 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.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    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);

    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_COPY);

    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] : (String) null), storageManager);
            if (files[i] == null) {
                // TODO @andomaex add failure Notification
                return Service.START_NOT_STICKY;
            }
        }
    }

    AccountManager aMgr = AccountManager.get(this);
    String version = aMgr.getUserData(account, Constants.KEY_OC_VERSION);
    OwnCloudVersion ocv = new OwnCloudVersion(version);

    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++) {
            uploadKey = buildRemoteName(account, files[i].getRemotePath());
            newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite,
                    localAction, getApplicationContext());
            if (isInstant) {
                newUpload.setRemoteFolderToBeCreated();
            }
            mPendingUploads.putIfAbsent(uploadKey, newUpload); // Grants that the file only upload once time

            newUpload.addDatatransferProgressListener(this);
            newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
            requestedUploads.add(uploadKey);
        }

    } 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);
    }
    Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
    return Service.START_NOT_STICKY;
}

From source file:com.hivewallet.androidclient.wallet.service.BlockchainServiceImpl.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent
                + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                        ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")"
                        : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();//from   w w  w . j ava2 s . c  o  m
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = new Sha256Hash(
                    intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}