Example usage for android.content Intent getLongArrayExtra

List of usage examples for android.content Intent getLongArrayExtra

Introduction

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

Prototype

public long[] getLongArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

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

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;/*from www.j a va2s  .co  m*/
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(getShareStatus(this, extraSubject, extraText));
    final int selection_end = mEditText.length();
    mEditText.setSelection(selection_end);
    return true;
}

From source file:net.xisberto.phonetodesktop.network.GoogleTasksService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        Utils.log("onHandleIntent " + intent.getAction());
        long[] tasks_ids;
        try {/*from   w  w w. ja va 2s .  c  om*/
            if (action.equals(Utils.ACTION_PROCESS_TASK)) {
                long task_id = intent.getLongExtra(Utils.EXTRA_TASK_ID, -1);
                LocalTask task = DatabaseHelper.getInstance(this).getTask(task_id);
                final Intent result = new Intent(Utils.ACTION_RESULT_PROCESS_TASK);
                result.putExtra(Utils.EXTRA_TASK_ID, task.getLocalId());
                if (isOnline()) {
                    processOptions(task);
                    task.persistBlocking(new PersistCallback() {
                        @Override
                        public void run() {
                            if (cache_unshorten != null) {
                                result.putExtra(Utils.EXTRA_CACHE_UNSHORTEN, cache_unshorten);
                            }
                            if (cache_titles != null) {
                                result.putExtra(Utils.EXTRA_CACHE_TITLES, cache_titles);
                            }
                            LocalBroadcastManager.getInstance(GoogleTasksService.this).sendBroadcast(result);
                        }
                    });
                } else {
                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                    revertTaskToReady(tasks_ids);
                    LocalBroadcastManager.getInstance(this).sendBroadcast(result);
                }
            } else if (action.equals(Utils.ACTION_SEND_TASKS)) {
                if (isOnline()) {

                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);

                    if (tasks_ids.length == 1) {
                        DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this);
                        LocalTask task = databaseHelper.getTask(tasks_ids[0]);
                        handleActionSend(task);
                    } else {
                        handleActionSendMultiple(tasks_ids);
                    }

                    stopForeground(true);
                } else {
                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                    revertTaskToReady(tasks_ids);
                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(
                            NOTIFICATION_SEND_LATER, buildNotification(NOTIFICATION_SEND_LATER).build());
                }
            } else if (action.equals(Utils.ACTION_LIST_TASKS)) {
                handleActionList();
            } else if (action.equals(Utils.ACTION_REMOVE_TASKS)) {
                handleActionRemove(intent.getStringArrayListExtra(Utils.EXTRA_TASKS_IDS));
            }
        } catch (UserRecoverableAuthIOException userRecoverableException) {
            Utils.log(Log.getStackTraceString(userRecoverableException));
            stopForeground(true);
            tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
            revertTaskToReady(tasks_ids);
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_NEED_AUTHORIZE,
                    buildNotification(NOTIFICATION_NEED_AUTHORIZE).build());
        } catch (IOException ioException) {
            Utils.log(Log.getStackTraceString(ioException));
            if (action.equals(Utils.ACTION_SEND_TASKS)) {
                tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                stopForeground(true);
                revertTaskToReady(tasks_ids);
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ERROR,
                        buildNotification(NOTIFICATION_ERROR).build());
            } else {
                Intent broadcast = new Intent(Utils.ACTION_LIST_TASKS);
                broadcast.putExtra(Utils.EXTRA_ERROR_TEXT, getString(R.string.txt_error_list));
                LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
            }
        } catch (NullPointerException npe) {
            tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
            Utils.log(Log.getStackTraceString(npe));
            stopForeground(true);
            revertTaskToReady(tasks_ids);
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_NEED_AUTHORIZE,
                    buildNotification(NOTIFICATION_NEED_AUTHORIZE).build());
        }
    }
}

From source file:com.android.contacts.ContactSaveService.java

private void deleteMultipleContacts(Intent intent) {
    final long[] contactIds = intent.getLongArrayExtra(EXTRA_CONTACT_IDS);
    if (contactIds == null) {
        Log.e(TAG, "Invalid arguments for deleteMultipleContacts request");
        return;/*  ww  w  .jav  a  2s .  c  o  m*/
    }
    for (long contactId : contactIds) {
        final Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
        getContentResolver().delete(contactUri, null, null);
    }
    final String[] names = intent.getStringArrayExtra(ContactSaveService.EXTRA_DISPLAY_NAME_ARRAY);
    final String deleteToastMessage;
    if (contactIds.length != names.length || names.length == 0) {
        deleteToastMessage = getResources().getQuantityString(R.plurals.contacts_deleted_toast,
                contactIds.length);
    } else if (names.length == 1) {
        deleteToastMessage = getResources().getString(R.string.contacts_deleted_one_named_toast, names);
    } else if (names.length == 2) {
        deleteToastMessage = getResources().getString(R.string.contacts_deleted_two_named_toast, names);
    } else {
        deleteToastMessage = getResources().getString(R.string.contacts_deleted_many_named_toast, names);
    }

    mMainHandler.post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(ContactSaveService.this, deleteToastMessage, Toast.LENGTH_LONG).show();
        }
    });
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private boolean handleDefaultIntent(final Intent intent) {
    if (intent == null)
        return false;
    final String action = intent.getAction();
    final boolean hasAccountIds;
    if (intent.hasExtra(EXTRA_ACCOUNT_IDS)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongArrayExtra(EXTRA_ACCOUNT_IDS));
        hasAccountIds = true;//  www . j a v  a 2 s  .  co m
    } else if (intent.hasExtra(EXTRA_ACCOUNT_ID)) {
        mAccountsAdapter.setSelectedAccountIds(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
        hasAccountIds = true;
    } else {
        hasAccountIds = false;
    }
    mShouldSaveAccounts = !Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)
            && !hasAccountIds;
    final Uri data = intent.getData();
    final CharSequence extraSubject = intent.getCharSequenceExtra(Intent.EXTRA_SUBJECT);
    final CharSequence extraText = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
    final Uri extraStream = intent.getParcelableExtra(Intent.EXTRA_STREAM);
    //TODO handle share_screenshot extra (Bitmap)
    if (extraStream != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, extraStream, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (data != null) {
        AsyncTaskUtils.executeTask(
                new AddMediaTask(this, data, createTempImageUri(), ParcelableMedia.TYPE_IMAGE, false));
    } else if (intent.hasExtra(EXTRA_SHARE_SCREENSHOT) && Utils.useShareScreenshot()) {
        final Bitmap bitmap = intent.getParcelableExtra(EXTRA_SHARE_SCREENSHOT);
        if (bitmap != null) {
            try {
                AsyncTaskUtils.executeTask(
                        new AddBitmapTask(this, bitmap, createTempImageUri(), ParcelableMedia.TYPE_IMAGE));
            } catch (IOException e) {
                // ignore
                bitmap.recycle();
            }
        }
    }
    mEditText.setText(Utils.getShareStatus(this, extraSubject, extraText));
    final int selectionEnd = mEditText.length();
    mEditText.setSelection(selectionEnd);
    return true;
}

From source file:com.android.contacts.ContactSaveService.java

private void joinSeveralContacts(Intent intent) {
    final long[] contactIds = intent.getLongArrayExtra(EXTRA_CONTACT_IDS);

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER);

    // Load raw contact IDs for all contacts involved.
    final long rawContactIds[] = getRawContactIdsForAggregation(contactIds);
    final long[][] separatedRawContactIds = getSeparatedRawContactIds(contactIds);
    if (rawContactIds == null) {
        Log.e(TAG, "Invalid arguments for joinSeveralContacts request");
        if (receiver != null) {
            receiver.send(BAD_ARGUMENTS, new Bundle());
        }//  w w  w  .ja v  a 2s  .c o m
        return;
    }

    // For each pair of raw contacts, insert an aggregation exception
    final ContentResolver resolver = getContentResolver();
    // The maximum number of operations per batch (aka yield point) is 500. See b/22480225
    final int batchSize = MAX_CONTACTS_PROVIDER_BATCH_SIZE;
    final ArrayList<ContentProviderOperation> operations = new ArrayList<>(batchSize);
    for (int i = 0; i < rawContactIds.length; i++) {
        for (int j = 0; j < rawContactIds.length; j++) {
            if (i != j) {
                buildJoinContactDiff(operations, rawContactIds[i], rawContactIds[j]);
            }
            // Before we get to 500 we need to flush the operations list
            if (operations.size() > 0 && operations.size() % batchSize == 0) {
                if (!applyOperations(resolver, operations)) {
                    if (receiver != null) {
                        receiver.send(CP2_ERROR, new Bundle());
                    }
                    return;
                }
                operations.clear();
            }
        }
    }
    if (operations.size() > 0 && !applyOperations(resolver, operations)) {
        if (receiver != null) {
            receiver.send(CP2_ERROR, new Bundle());
        }
        return;
    }

    final String name = queryNameOfLinkedContacts(contactIds);
    if (name != null) {
        if (receiver != null) {
            final Bundle result = new Bundle();
            result.putSerializable(EXTRA_RAW_CONTACT_IDS, separatedRawContactIds);
            result.putString(EXTRA_DISPLAY_NAME, name);
            receiver.send(CONTACTS_LINKED, result);
        } else {
            if (TextUtils.isEmpty(name)) {
                showToast(R.string.contactsJoinedMessage);
            } else {
                showToast(R.string.contactsJoinedNamedMessage, name);
            }
        }
        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_LINK_COMPLETE));
    } else {
        if (receiver != null) {
            receiver.send(CP2_ERROR, new Bundle());
        }
        showToast(R.string.contactJoinErrorToast);
    }
}

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

private int handleIntent(final Intent intent, final boolean firstCreate) {
    // use packge's class loader to prevent BadParcelException
    intent.setExtrasClassLoader(getClassLoader());
    // reset intent
    setIntent(new Intent(this, HomeActivity.class));
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
        final long accountId;
        if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
            accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
        } else {//from w w w. j av a 2 s  . c om
            accountId = getDefaultAccountId(this);
        }
        openSearch(this, accountId, query);
        return -1;
    }
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_REFRESH_IDS);
    if (refreshedIds != null) {
        mTwitterWrapper.refreshAll(refreshedIds);
    } else if (firstCreate && refreshOnStart) {
        mTwitterWrapper.refreshAll();
    }

    final Uri uri = intent.getData();
    final String tabType = uri != null ? Utils.matchTabType(uri) : null;
    int initialTab = -1;
    if (tabType != null) {
        final long accountId = ParseUtils.parseLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID));
        for (int i = mPagerAdapter.getCount() - 1; i > -1; i--) {
            final SupportTabSpec tab = mPagerAdapter.getTab(i);
            if (tabType.equals(tab.type)) {
                initialTab = i;
                if (hasAccountId(tab.args, accountId)) {
                    break;
                }
            }
        }
    }
    if (initialTab != -1 && mViewPager != null) {
        // clearNotification(initial_tab);
    }
    final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
    if (extraIntent != null && firstCreate) {
        extraIntent.setExtrasClassLoader(getClassLoader());
        startActivity(extraIntent);
    }
    return initialTab;
}

From source file:com.android.contacts.ContactSaveService.java

private void updateGroup(Intent intent) {
    long groupId = intent.getLongExtra(EXTRA_GROUP_ID, -1);
    String label = intent.getStringExtra(EXTRA_GROUP_LABEL);
    long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD);
    long[] rawContactsToRemove = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_REMOVE);

    if (groupId == -1) {
        Log.e(TAG, "Invalid arguments for updateGroup request");
        return;//from  www.  j  a v  a  2  s  .c om
    }

    final ContentResolver resolver = getContentResolver();
    final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, groupId);

    // Update group name if necessary
    if (label != null) {
        ContentValues values = new ContentValues();
        values.put(Groups.TITLE, label);
        resolver.update(groupUri, values, null, null);
    }

    // Add and remove members if necessary
    addMembersToGroup(resolver, rawContactsToAdd, groupId);
    removeMembersFromGroup(resolver, rawContactsToRemove, groupId);

    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    callbackIntent.setData(groupUri);
    deliverCallback(callbackIntent);
}

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

private int handleIntent(final Intent intent, final boolean firstCreate) {
    // use packge's class loader to prevent BadParcelException
    intent.setExtrasClassLoader(getClassLoader());
    // reset intent
    setIntent(new Intent(this, HomeActivity.class));
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        final Bundle appSearchData = intent.getBundleExtra(SearchManager.APP_DATA);
        final long accountId;
        if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
            accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
        } else {//from  www .j a  va 2  s. com
            accountId = getDefaultAccountId(this);
        }
        openSearch(this, accountId, query);
        return -1;
    }
    final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
    final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_IDS);
    if (refreshedIds != null) {
        mTwitterWrapper.refreshAll(refreshedIds);
    } else if (firstCreate && refreshOnStart) {
        mTwitterWrapper.refreshAll();
    }

    final int tab = intent.getIntExtra(EXTRA_INITIAL_TAB, -1);
    final int initialTab = tab != -1 ? tab : getAddedTabPosition(this, intent.getStringExtra(EXTRA_TAB_TYPE));
    if (initialTab != -1 && mViewPager != null) {
        // clearNotification(initial_tab);
    }
    final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
    if (extraIntent != null && firstCreate) {
        extraIntent.setExtrasClassLoader(getClassLoader());
        SwipebackActivityUtils.startSwipebackActivity(this, extraIntent);
    }
    return initialTab;
}

From source file:com.android.contacts.ContactSaveService.java

private void createGroup(Intent intent) {
    String accountType = intent.getStringExtra(EXTRA_ACCOUNT_TYPE);
    String accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME);
    String dataSet = intent.getStringExtra(EXTRA_DATA_SET);
    String label = intent.getStringExtra(EXTRA_GROUP_LABEL);
    final long[] rawContactsToAdd = intent.getLongArrayExtra(EXTRA_RAW_CONTACTS_TO_ADD);

    // Create the new group
    final Uri groupUri = mGroupsDao.create(label, new AccountWithDataSet(accountName, accountType, dataSet));
    final ContentResolver resolver = getContentResolver();

    // If there's no URI, then the insertion failed. Abort early because group members can't be
    // added if the group doesn't exist
    if (groupUri == null) {
        Log.e(TAG, "Couldn't create group with label " + label);
        return;//from   w w w . j ava 2  s .c o m
    }

    // Add new group members
    addMembersToGroup(resolver, rawContactsToAdd, ContentUris.parseId(groupUri));

    ContentValues values = new ContentValues();
    // TODO: Move this into the contact editor where it belongs. This needs to be integrated
    // with the way other intent extras that are passed to the
    // {@link ContactEditorActivity}.
    values.clear();
    values.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE);
    values.put(GroupMembership.GROUP_ROW_ID, ContentUris.parseId(groupUri));

    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    callbackIntent.setData(groupUri);
    // TODO: This can be taken out when the above TODO is addressed
    callbackIntent.putExtra(ContactsContract.Intents.Insert.DATA, Lists.newArrayList(values));
    deliverCallback(callbackIntent);
}

From source file:com.tingtingapps.securesms.ConversationActivity.java

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    Log.w(TAG, "onActivityResult called: " + reqCode + ", " + resultCode + " , " + data);
    super.onActivityResult(reqCode, resultCode, data);

    if (data == null && reqCode != TAKE_PHOTO || resultCode != RESULT_OK)
        return;//  w w  w .  j a  va  2 s.  c  om

    switch (reqCode) {
    case PICK_IMAGE:
        addAttachmentImage(masterSecret, data.getData());
        break;
    case PICK_VIDEO:
        addAttachmentVideo(data.getData());
        break;
    case PICK_AUDIO:
        addAttachmentAudio(data.getData());
        break;
    case PICK_CONTACT_INFO:
        addAttachmentContactInfo(data.getData());
        break;
    case GROUP_EDIT:
        this.recipients = RecipientFactory.getRecipientsForIds(this,
                data.getLongArrayExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA), true);
        titleView.setTitle(recipients);
        setBlockedUserState(recipients);
        supportInvalidateOptionsMenu();
        break;
    case TAKE_PHOTO:
        if (attachmentManager.getCaptureUri() != null) {
            addAttachmentImage(masterSecret, attachmentManager.getCaptureUri());
        }
        break;
    }
}