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:org.getlantern.firetweet.fragment.support.StatusFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_SET_COLOR: {
        final ParcelableStatus status = mStatusAdapter.getStatus();
        if (status == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null)
                return;
            final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT);
            setUserColor(getActivity(), status.user_id, color);
        } else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) {
            clearUserColor(getActivity(), status.user_id);
        }/*from w ww.j  av a 2s.c om*/
        break;
    }
    case REQUEST_SELECT_ACCOUNT: {
        final ParcelableStatus status = mStatusAdapter.getStatus();
        if (status == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null || !data.hasExtra(EXTRA_ID))
                return;
            final long accountId = data.getLongExtra(EXTRA_ID, -1);
            openStatus(getActivity(), accountId, status.id);
        }
        break;
    }
    }
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private boolean handleIntent(final Intent intent) {
    final String action = intent.getAction();
    mShouldSaveAccounts = false;/*w w  w. j  a v a  2 s .  c o m*/
    mMentionUser = intent.getParcelableExtra(EXTRA_USER);
    mInReplyToStatus = intent.getParcelableExtra(EXTRA_STATUS);
    mInReplyToStatusId = mInReplyToStatus != null ? mInReplyToStatus.id : -1;
    if (INTENT_ACTION_REPLY.equals(action))
        return handleReplyIntent(mInReplyToStatus);
    else if (INTENT_ACTION_QUOTE.equals(action))
        return handleQuoteIntent(mInReplyToStatus);
    else if (INTENT_ACTION_EDIT_DRAFT.equals(action)) {
        mDraftItem = intent.getParcelableExtra(EXTRA_DRAFT);
        return handleEditDraftIntent(mDraftItem);
    } else if (INTENT_ACTION_MENTION.equals(action))
        return handleMentionIntent(mMentionUser);
    else if (INTENT_ACTION_REPLY_MULTIPLE.equals(action)) {
        final String[] screenNames = intent.getStringArrayExtra(EXTRA_SCREEN_NAMES);
        final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1);
        final long inReplyToUserId = intent.getLongExtra(EXTRA_IN_REPLY_TO_ID, -1);
        return handleReplyMultipleIntent(screenNames, accountId, inReplyToUserId);
    } else if (INTENT_ACTION_COMPOSE_TAKE_PHOTO.equals(action)) {
        takePhoto();
        return true;
    } else if (INTENT_ACTION_COMPOSE_PICK_IMAGE.equals(action)) {
        pickImage();
        return true;
    }
    // Unknown action or no intent extras
    return false;
}

From source file:com.ywesee.amiko.MainActivity.java

/**
 * Overrides onCreate method/*from  w w w  .j  a  va2 s .co  m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        AsyncLoadDBTask loadDBTask = new AsyncLoadDBTask(this);
        loadDBTask.execute();
    } catch (Exception e) {
        Log.e(TAG, "AsyncLoadDBTask exception caught!");
    }

    // Load CSS from asset folder
    if (Utilities.isTablet(this))
        mCSS_str = Utilities.loadFromAssetsFolder(this, "amiko_stylesheet.css", "UTF-8");
    else
        mCSS_str = Utilities.loadFromAssetsFolder(this, "amiko_stylesheet_phone.css", "UTF-8");

    // Flag for enabling the Action Bar on top
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    // Enable overlay mode for action bar (no good, search results disappear behind it...)
    // getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    // Create action bar
    int mode = ActionBar.NAVIGATION_MODE_TABS;
    if (savedInstanceState != null) {
        mode = savedInstanceState.getInt("mode", ActionBar.NAVIGATION_MODE_TABS);
    }

    // Sets tab bar items
    addTabNavigation();

    // Reset action name
    Log.d(TAG, "OnCreate -> " + mActionName);
    mActionName = getString(R.string.tab_name_1);

    /*
    'getFilesDir' returns a java.io.File object representing the root directory
    of the INTERNAL storage four the application from the current context.
    */
    mFavoriteData = new DataStore(this.getFilesDir().toString());
    // Load hashset containing registration numbers from persistent data store
    mFavoriteMedsSet = new HashSet<String>();
    mFavoriteMedsSet = mFavoriteData.load();

    // Initialize preferences
    SharedPreferences settings = getSharedPreferences(AMIKO_PREFS_FILE, 0);

    long timeMillisSince1970 = 0;
    if (Constants.appLanguage().equals("de")) {
        timeMillisSince1970 = settings.getLong(PREF_DB_UPDATE_DATE_DE, 0);
        if (timeMillisSince1970 == 0) {
            SharedPreferences.Editor editor = settings.edit();
            editor.putLong(PREF_DB_UPDATE_DATE_DE, System.currentTimeMillis());
            // Commit the edits!
            editor.commit();
        }
    } else if (Constants.appLanguage().equals("fr")) {
        timeMillisSince1970 = settings.getLong(PREF_DB_UPDATE_DATE_FR, 0);
        if (timeMillisSince1970 == 0) {
            SharedPreferences.Editor editor = settings.edit();
            editor.putLong(PREF_DB_UPDATE_DATE_DE, System.currentTimeMillis());
            // Commit the edits!
            editor.commit();
        }
    }

    checkTimeSinceLastUpdate();

    // Init toast object
    mToastObject = new CustomToast(this);

    // Initialize download manager
    mDownloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

    mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                if (downloadId == mDatabaseId || downloadId == mReportId || downloadId == mInteractionsId)
                    mDownloadedFileCount++;
                // Before proceeding make sure all files have been downloaded before proceeding
                if (mDownloadedFileCount == 3) {
                    Query query = new Query();
                    query.setFilterById(downloadId);
                    Cursor c = mDownloadManager.query(query);
                    if (c.moveToFirst()) {
                        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                        // Check if download was successful
                        if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                            try {
                                // Update database
                                AsyncUpdateDBTask updateDBTask = new AsyncUpdateDBTask(MainActivity.this);
                                updateDBTask.execute();
                            } catch (Exception e) {
                                Log.e(TAG, "AsyncUpdateDBTask: exception caught!");
                            }
                            // Toast
                            mToastObject.show("Databases downloaded successfully. Installing...",
                                    Toast.LENGTH_SHORT);
                            if (mProgressBar.isShowing())
                                mProgressBar.dismiss();
                            mUpdateInProgress = false;
                            // Store time stamp
                            SharedPreferences settings = getSharedPreferences(AMIKO_PREFS_FILE, 0);
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putLong(PREF_DB_UPDATE_DATE_DE, System.currentTimeMillis());
                            // Commit the edits!
                            editor.commit();
                        } else {
                            mToastObject.show("Error while downloading database...", Toast.LENGTH_SHORT);
                        }
                    }
                    c.close();
                }
            }
        }
    };
    registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java

private void doResolveIntent(Intent intent) {

    if (requireOpenDashboardOnStart(intent)) {
        long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1L);
        mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L);
        if (providerId == -1L || mLastAccountId == -1L) {
            finish();/*  w ww  .j  a  va  2s  .c  om*/
        } else {
            //   mChatSwitcher.open();
        }
        return;
    }

    if (ImServiceConstants.ACTION_MANAGE_SUBSCRIPTION.equals(intent.getAction())) {

        long providerId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, -1);
        mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L);
        String from = intent.getStringExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS);

        if ((providerId == -1) || (from == null)) {
            finish();
        } else {

            showSubscriptionDialog(providerId, from);

        }
    } else if (intent != null) {
        Uri data = intent.getData();

        if (intent.getBooleanExtra("showaccounts", false))
            mDrawer.openDrawer(GravityCompat.START);

        if (data != null) {
            if (data.getScheme() != null && data.getScheme().equals("immu")) {
                String user = data.getUserInfo();
                String host = data.getHost();
                String path = null;

                if (data.getPathSegments().size() > 0)
                    path = data.getPathSegments().get(0);

                if (host != null && path != null) {

                    IImConnection connMUC = findConnectionForGroupChat(user, host);

                    if (connMUC != null) {

                        startGroupChat(path, host, user, connMUC);
                        setResult(RESULT_OK);
                    } else {
                        mHandler.showAlert("Connection Error",
                                "Unable to find a connection to join a group chat from. Please sign in and try again.");
                        setResult(Activity.RESULT_CANCELED);
                        finish();
                    }

                }

            } else {

                String type = getContentResolver().getType(data);
                if (Imps.Chats.CONTENT_ITEM_TYPE.equals(type)) {

                    long requestedContactId = ContentUris.parseId(data);

                    Cursor cursorChats = mChatPagerAdapter.getCursor();

                    if (cursorChats != null) {
                        cursorChats.moveToPosition(-1);
                        int posIdx = 1;
                        boolean foundChatView = false;

                        while (cursorChats.moveToNext()) {
                            long chatId = cursorChats.getLong(ChatView.CONTACT_ID_COLUMN);

                            if (chatId == requestedContactId) {
                                mChatPager.setCurrentItem(posIdx);
                                foundChatView = true;
                                break;
                            }

                            posIdx++;
                        }

                        if (!foundChatView) {

                            Uri.Builder builder = Imps.Contacts.CONTENT_URI.buildUpon();
                            ContentUris.appendId(builder, requestedContactId);
                            Cursor cursor = getContentResolver().query(builder.build(),
                                    ChatView.CHAT_PROJECTION, null, null, null);

                            try {
                                if (cursor.getCount() > 0) {
                                    cursor.moveToFirst();
                                    openExistingChat(cursor);
                                }
                            } finally {
                                cursor.close();
                            }
                        }
                    }

                } else if (Imps.Invitation.CONTENT_ITEM_TYPE.equals(type)) {
                    //chatView.bindInvitation(ContentUris.parseId(data));

                }
            }
        } else if (intent.hasExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID)) {
            //set the current account id
            mLastAccountId = intent.getLongExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, -1L);

            //move the pager back to the first page
            if (mChatPager != null)
                mChatPager.setCurrentItem(0);

        } else {
            //  refreshConnections();
        }
    }

}

From source file:net.inbox.InboxGPG.java

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

    // Try again after user interaction
    if (resultCode == RESULT_OK) {
        /*/*from w w  w  .  j a  v a2s  . c om*/
         * The data originally given to one of the methods above, is again
         * returned here to be used when calling the method again after user
         * interaction. The Intent now also contains results from the user
         * interaction, for example selected key ids.
         */
        switch (requestCode) {
        case REQUEST_CODE_CLEARTEXT_SIGN: {
            cleartext_sign(data);
            break;
        }
        case REQUEST_CODE_DETACHED_SIGN: {
            detached_sign(data);
            break;
        }
        case REQUEST_CODE_ENCRYPT: {
            encrypt(data);
            break;
        }
        case REQUEST_CODE_SIGN_AND_ENCRYPT: {
            sign_and_encrypt(data);
            break;
        }
        case REQUEST_CODE_DECRYPT_AND_VERIFY: {
            decrypt_and_verify(data);
            break;
        }
        case REQUEST_CODE_GET_KEY_IDS: {
            get_rcpt_keys(data);
            break;
        }
        case REQUEST_CODE_DECRYPT_AND_VERIFY_DETACHED: {
            decrypt_and_verify_detached(data);
            break;
        }
        case REQUEST_CODE_KEY_PREFERENCE: {
            if (data == null) {
                l_sign_key_id = NO_KEY;
                tv_signing_key.setText(R.string.open_pgp_signing_key_cross);
            } else {
                l_sign_key_id = data.getLongExtra("sign_key_id", -1);
                tv_signing_key.setText(R.string.open_pgp_signing_key_check);
            }
            break;
        }
        }
    }
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean handleIntent(final Intent intent) {
    final String action = intent.getAction();
    mShouldSaveAccounts = false;//from  w  w w.  jav  a2s  .  co m
    mMentionUser = intent.getParcelableExtra(EXTRA_USER);
    mInReplyToStatus = intent.getParcelableExtra(EXTRA_STATUS);
    mInReplyToStatusId = mInReplyToStatus != null ? mInReplyToStatus.id : -1;
    switch (action) {
    case INTENT_ACTION_REPLY: {
        return handleReplyIntent(mInReplyToStatus);
    }
    case INTENT_ACTION_QUOTE: {
        return handleQuoteIntent(mInReplyToStatus);
    }
    case INTENT_ACTION_EDIT_DRAFT: {
        mDraftItem = intent.getParcelableExtra(EXTRA_DRAFT);
        return handleEditDraftIntent(mDraftItem);
    }
    case INTENT_ACTION_MENTION: {
        return handleMentionIntent(mMentionUser);
    }
    case INTENT_ACTION_REPLY_MULTIPLE: {
        final String[] screenNames = intent.getStringArrayExtra(EXTRA_SCREEN_NAMES);
        final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1);
        final long inReplyToUserId = intent.getLongExtra(EXTRA_IN_REPLY_TO_ID, -1);
        return handleReplyMultipleIntent(screenNames, accountId, inReplyToUserId);
    }
    case INTENT_ACTION_COMPOSE_TAKE_PHOTO: {
        return takePhoto();
    }
    case INTENT_ACTION_COMPOSE_PICK_IMAGE: {
        return pickImage();
    }
    }
    // Unknown action or no intent extras
    return false;
}

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    final ParcelableUser user = mUser;
    switch (requestCode) {
    case REQUEST_SET_COLOR: {
        if (user == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null)
                return;
            final int color = data.getIntExtra(EXTRA_COLOR, Color.TRANSPARENT);
            setUserColor(getActivity(), mUser.id, color);
        } else if (resultCode == ColorPickerDialogActivity.RESULT_CLEARED) {
            clearUserColor(getActivity(), mUser.id);
        }/*from  w w w  . jav a 2  s .  co m*/
        break;
    }
    case REQUEST_ADD_TO_LIST: {
        if (user == null)
            return;
        if (resultCode == Activity.RESULT_OK && data != null) {
            final AsyncTwitterWrapper twitter = getTwitterWrapper();
            final ParcelableUserList list = data.getParcelableExtra(EXTRA_USER_LIST);
            if (list == null || twitter == null)
                return;
            twitter.addUserListMembersAsync(user.account_id, list.id, user);
        }
        break;
    }
    case REQUEST_SELECT_ACCOUNT: {
        if (user == null)
            return;
        if (resultCode == Activity.RESULT_OK) {
            if (data == null || !data.hasExtra(EXTRA_ID))
                return;
            final long accountId = data.getLongExtra(EXTRA_ID, -1);
            openUserProfile(getActivity(), accountId, user.id, null);
        }
        break;
    }
    }

}

From source file:de.tubs.ibr.dtn.chat.service.ChatService.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    // create a task to process concurrently
    if (ACTION_PRESENCE_ALARM.equals(action)) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ChatService.this);

        // check if the screen is active
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        Boolean screenOn = pm.isScreenOn();

        String presence_tag = preferences.getString("presencetag", "auto");
        String presence_nick = preferences.getString("editNickname", "Nobody");
        String presence_text = preferences.getString("statustext", "");

        if (presence_tag.equals("auto")) {
            if (screenOn) {
                presence_tag = "chat";
            } else {
                presence_tag = "away";
            }/*from  ww  w  .  j ava  2  s.c o  m*/
        }

        Log.i(TAG, "push out presence; " + presence_tag);
        actionRefreshPresence(presence_tag, presence_nick, presence_text);

        Editor edit = preferences.edit();
        edit.putLong("lastpresenceupdate", (new Date().getTime()));
        edit.commit();
    }
    // create a task to check for messages
    else if (de.tubs.ibr.dtn.Intent.RECEIVE.equals(action)) {
        try {
            while (_client.getSession().queryNext())
                ;
        } catch (SessionDestroyedException e) {
            Log.e(TAG, "Can not query for bundle", e);
        } catch (InterruptedException e) {
            Log.e(TAG, "Can not query for bundle", e);
        }
    } else if (MARK_DELIVERED_INTENT.equals(action)) {
        actionMarkDelivered(intent);
    } else if (REPORT_DELIVERED_INTENT.equals(action)) {
        actionReportDelivered(intent);
    } else if (ACTION_SEND_MESSAGE.equals(action)) {
        Long buddyId = intent.getLongExtra(ChatService.EXTRA_BUDDY_ID, -1);
        String text = intent.getStringExtra(ChatService.EXTRA_TEXT_BODY);

        // abort if there is no buddyId
        if (buddyId < 0)
            return;

        actionSendMessage(buddyId, text);
    } else if (ACTION_REFRESH_PRESENCE.equals(action)) {
        String presence = intent.getStringExtra(ChatService.EXTRA_PRESENCE);
        String nickname = intent.getStringExtra(ChatService.EXTRA_DISPLAY_NAME);
        String status = intent.getStringExtra(ChatService.EXTRA_STATUS);

        actionRefreshPresence(presence, nickname, status);
    } else if (ACTION_NEW_MESSAGE.equals(action)) {
        showNotification(intent);
    }
}

From source file:org.openintents.notepad.NoteEditor.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (DEBUG) {//from   www  .ja v  a 2s.  com
        Log.d(TAG, "onActivityResult: Received requestCode " + requestCode + ", resultCode " + resultCode);
    }
    switch (requestCode) {
    case REQUEST_CODE_DECRYPT:
        if (resultCode == RESULT_OK && data != null) {
            String decryptedText = data.getStringExtra(CryptoIntents.EXTRA_TEXT);
            long id = data.getLongExtra(PrivateNotePadIntents.EXTRA_ID, -1);

            // TODO: Check that id corresponds to current intent.

            if (id == -1) {
                Log.e(TAG, "Wrong extra id");
                Toast.makeText(this, "Decrypted information incomplete", Toast.LENGTH_SHORT).show();

                finish();
                return;
            }

            if (DEBUG) {
                Log.d(TAG, "decrypted text received: " + decryptedText);
            }
            mDecryptedText = decryptedText;
            mOriginalContent = decryptedText;

        } else {
            Toast.makeText(this, R.string.decryption_failed, Toast.LENGTH_SHORT).show();
            Log.e(TAG, "decryption failed");

            finish();
        }
        break;
    case REQUEST_CODE_TEXT_SELECTION_ALTERNATIVE:
        if (resultCode == RESULT_OK && data != null) {
            // Insert result at current cursor position:
            mApplyText = data.getStringExtra(NotepadIntents.EXTRA_TEXT);
            mApplyTextBefore = data.getStringExtra(NotepadIntents.EXTRA_TEXT_BEFORE_SELECTION);
            mApplyTextAfter = data.getStringExtra(NotepadIntents.EXTRA_TEXT_AFTER_SELECTION);

            // Text is actually inserted in onResume() - see
            // applyInsertText()
        }
        break;
    case REQUEST_CODE_SAVE_AS:
        if (resultCode == RESULT_OK && data != null) {
            // Set the new file name
            mUri = data.getData();
            if (DEBUG) {
                Log.d(TAG, "original: " + mOriginalContent + ", file: " + mFileContent);
            }
            mOriginalContent = mFileContent;

            updateTitleSdCard();
        }
        break;
    }
}

From source file:saphion.fragments.alarm.AlarmFragment.java

@Override
public void onResume() {
    super.onResume();
    // 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();//from w w  w.  j  a  v  a2 s .c  om
        }

        // 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);
    }

    // Make sure to use the child FragmentManager. We have to use that one
    // for the
    // case where an intent comes in telling the activity to load the
    // timepicker,
    // which means we have to use that one everywhere so that the fragment
    // can get
    // correctly picked up here if it's open.
    /*
     * TimePickerDialog tpd = (TimePickerDialog) getFragmentManager()
     * .findFragmentByTag(AlarmUtils.FRAG_TAG_TIME_PICKER); if (tpd != null)
     * { // The dialog is already open so we need to set the listener again.
     * tpd.setOnTimeSetListener(this); }
     */
}