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.tumanako.dash.DashMessages.java

@Override
public void onReceive(Context context, Intent intent) {

    // Get the 'Action' from the intent:
    String action = intent.getAction();

    // Get other data (if it was sent):
    Integer intData = null;/*from   w w  w.ja v a  2  s .  co m*/
    Float floatData = null;
    String stringData = null;
    Bundle bundleData = null;

    if (intent.hasExtra(DASHMESSAGE_INT))
        intData = intent.getIntExtra(DASHMESSAGE_INT, 0);
    if (intent.hasExtra(DASHMESSAGE_FLOAT))
        floatData = intent.getFloatExtra(DASHMESSAGE_FLOAT, 0f);
    if (intent.hasExtra(DASHMESSAGE_STRING))
        stringData = intent.getStringExtra(DASHMESSAGE_STRING);
    if (intent.hasExtra(DASHMESSAGE_DATA))
        bundleData = intent.getBundleExtra(DASHMESSAGE_DATA);

    // --DEBUG!-- Log.i(com.tumanako.ui.UIActivity.APP_TAG, String.format( " DashMessages -> Msg Rec: %d", message) );

    parent.messageReceived(action, intData, floatData, stringData, bundleData);
}

From source file:com.krayzk9s.imgurholo.services.UploadService.java

@Override
protected void onHandleIntent(Intent intent) {
    ids = new ArrayList<String>();
    if (intent.hasExtra("images")) {
        Log.d("recieving", "handling multiple");
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra("images");
        totalUpload = list.size();/*from  w  ww . ja va  2 s  . com*/
        for (Parcelable parcel : list) {
            Uri uri = (Uri) parcel;
            Log.d("recieving", uri.toString());
            SendImage sendImage = new SendImage(apiCall, FileUtils.getPath(this, uri), getApplicationContext(),
                    getResources(), this);
            Log.d("recieving", "executing");
            sendImage.execute();
        }
    } else {
        totalUpload = -1;
        SendImage sendImage = new SendImage(apiCall,
                FileUtils.getPath(getApplicationContext(), intent.getData()), getApplicationContext(),
                getResources(), this);
        sendImage.execute();
    }
}

From source file:com.example.RITW.Ble.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
    //      mLogSession = Logger.openSession(getApplicationContext(), logUri);
    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);

    //      Logger.i(mLogSession, "Service started");

    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();/*  ww w .ja  v a2  s .c o m*/
    onServiceStarted();

    //      Logger.v(mLogSession, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:com.google.samples.apps.iosched.service.SessionCalendarService.java

/**
 * Gets the currently-logged in user's Google Calendar, or the Google Calendar for the user
 * specified in the given intent's {@link #EXTRA_ACCOUNT_NAME}.
 *//*from ww  w . ja va2  s.  c  o m*/
private long getCalendarId(Intent intent) {
    final String accountName;
    if (intent != null && intent.hasExtra(EXTRA_ACCOUNT_NAME)) {
        accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
    } else {
        accountName = AccountUtils.getActiveAccountName(this);
    }

    if (TextUtils.isEmpty(accountName) || !permissionsAlreadyGranted()) {
        return INVALID_CALENDAR_ID;
    }

    // TODO: The calendar ID should be stored in shared settings_prefs upon choosing an account.
    @SuppressWarnings("MissingPermission")
    Cursor calendarsCursor = getContentResolver().query(CalendarContract.Calendars.CONTENT_URI,
            new String[] { "_id" },
            // TODO: What if the calendar is not displayed or not sync'd?
            "account_name = ownerAccount and account_name = ?", new String[] { accountName }, null);

    long calendarId = INVALID_CALENDAR_ID;
    if (calendarsCursor != null && calendarsCursor.moveToFirst()) {
        calendarId = calendarsCursor.getLong(0);
        calendarsCursor.close();
    }

    return calendarId;
}

From source file:com.germainz.identiconizer.services.IdenticonCreationService.java

@Override
protected void onHandleIntent(Intent intent) {
    startForeground(SERVICE_NOTIFICATION_ID, createNotification());
    // If a predefined contacts list is provided, use it directly.
    // contactsList is set when this service is started from ContactsListActivity.
    if (intent.hasExtra("contactsList")) {
        ArrayList<ContactInfo> contactsList = intent.getParcelableArrayListExtra("contactsList");
        processContacts(contactsList);//from   w  w w  .jav  a 2  s .  c  om
    } else {
        // If updateExisting is set to false, only contacts without a picture will get a new one.
        // Otherwise, even those that have an identicon set will get a new one. The latter is useful
        // when changing identicon styles, but is a waste of time when we're starting this service
        // after a new contact has been added. In that case, we just want the new contact to get his
        // identicon.
        boolean updateExisting = intent.getBooleanExtra("updateExisting", true);
        processContacts(updateExisting);
    }
    if (mUpdateErrors.size() > 0 || mInsertErrors.size() > 0)
        createNotificationForError();
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("CONTACTS_UPDATED"));
    getContentResolver().notifyChange(ContactsContract.Data.CONTENT_URI, null);
    stopForeground(true);
}

From source file:com.diy.blelib.profile.BleProfileService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
        throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

    mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
    Log.i(TAG, "Service started");
    //?????/*from w w w. j  a va2s  .c o  m*/
    if (!mBlutoothAdapter.isEnabled())
        mBlutoothAdapter.enable();
    // notify user about changing the state to CONNECTING
    final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
    broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
    LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    final BluetoothAdapter adapter = bluetoothManager.getAdapter();
    final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
    mDeviceName = device.getName();
    onServiceStarted();

    Log.v(TAG, "Connecting...");
    mBleManager.connect(BleProfileService.this, device);
    return START_REDELIVER_INTENT;
}

From source file:com.josephblough.sbt.activities.ShortcutActivity.java

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

    // If criteria has been selected then load the details data
    if (resultCode == RESULT_OK && data != null && data.hasExtra(SEARCH_TYPE)) {
        final int searchType = data.getIntExtra(SEARCH_TYPE, 0);
        final String criteria = data.getStringExtra(CRITERIA);

        createLauncher(searchType, criteria);
    } else {/* w ww.  j av a2s.co m*/
        setResult(RESULT_CANCELED, new Intent());
        finish();
    }
}

From source file:de.da_sense.moses.client.RunningFragment.java

@Override
public void onResume() {
    super.onResume();
    refreshInstalledApplications();/*from   www .  ja v a  2 s  . c  o  m*/
    Intent startingIntent = mActivity.getIntent();
    if (startingIntent.hasExtra(WelcomeActivity.KEY_VIEW_SURVEY)) {
        // some other activity has started the parent activity in order to show an available survey, show it god damn it
        String apkID = startingIntent.getStringExtra(WelcomeActivity.KEY_VIEW_SURVEY);
        startingIntent.removeExtra(WelcomeActivity.KEY_VIEW_SURVEY); // remove the extra from the intent because already processed
        // obtain the view responsible for the apk
        final Integer positionOfTheView = mApkPositions.get(apkID);
        if (positionOfTheView == null || installedApps.size() <= positionOfTheView) {
            // the could already be in history tab, for example when the user fills the survey and then
            // tries to fill it again by following the status bar notification
            Log.i(LOG_TAG,
                    "onResume() the apk is no longer in the list, the user may have already filled the survey");
            Toaster.showToast(mActivity, getString(R.string.notification_user_study_not_available));
        } else {
            showDetails(positionOfTheView, mActivity, new Runnable() {
                @Override
                public void run() {
                    handleStartApp(getInstalledApps().get(positionOfTheView));
                }
            }, new Runnable() {
                @Override
                public void run() {
                }
            });
        }
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockToggle.java

@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
    mServiceInterface = ITapLockService.Stub.asInterface(binder);
    if (mUIInterface != null) {
        try {/* ww  w. j  a  v  a  2  s  .c o m*/
            mServiceInterface.setCallback(mUIInterface);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString());
        }
    }
    Intent intent = getIntent();
    if (intent != null) {
        String action = intent.getAction();
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)
                && intent.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
            Log.d(TAG, "service connected, NDEF_DISCOVERED");
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage message;
            if (rawMsgs != null) {
                // process the first message
                message = (NdefMessage) rawMsgs[0];
                // process the first record
                NdefRecord record = message.getRecords()[0];
                if (record.getTnf() == NdefRecord.TNF_WELL_KNOWN) {
                    try {
                        byte[] payload = record.getPayload();
                        /*
                         * payload[0] contains the "Status Byte Encodings" field, per the
                         * NFC Forum "Text Record Type Definition" section 3.2.1.
                         *
                         * bit7 is the Text Encoding Field.
                         *
                         * if (Bit_7 == 0): The text is encoded in UTF-8 if (Bit_7 == 1):
                         * The text is encoded in UTF16
                         *
                         * Bit_6 is reserved for future use and must be set to zero.
                         *
                         * Bits 5 to 0 are the length of the IANA language code.
                         */
                        String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
                        int languageCodeLength = payload[0] & 0077;
                        String taggedDeviceName = new String(payload, languageCodeLength + 1,
                                payload.length - languageCodeLength - 1, textEncoding);
                        manageDevice(taggedDeviceName, ACTION_TOGGLE);
                    } catch (UnsupportedEncodingException e) {
                        // should never happen unless we get a malformed tag.
                        Log.e(TAG, e.toString());
                        finish();
                    }
                } else
                    finish();
            } else
                finish();
        } else if (intent.getData() != null) {
            String taggedDeviceName = intent.getData().getHost();
            if (taggedDeviceName != null)
                manageDevice(taggedDeviceName, ACTION_TOGGLE);
            else
                finish();
        } else if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action))
            manageDevice(intent.getStringExtra(EXTRA_DEVICE_NAME), action);
        else
            finish();
    } else
        finish();
}

From source file:com.demo.firebase.MainActivity.java

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Check if this Activity was launched by clicking on an upload notification
    if (intent.hasExtra(MyUploadService.EXTRA_DOWNLOAD_URL)) {
        onUploadResultIntent(intent);/*  www  .j  a  va  2s  .com*/
    }

}