List of usage examples for android.content Intent getParcelableExtra
public <T extends Parcelable> T getParcelableExtra(String name)
From source file:com.android.contacts.ContactSaveService.java
private void setSendToVoicemail(Intent intent) { Uri contactUri = intent.getParcelableExtra(EXTRA_CONTACT_URI); boolean value = intent.getBooleanExtra(EXTRA_SEND_TO_VOICEMAIL_FLAG, false); if (contactUri == null) { Log.e(TAG, "Invalid arguments for setRedirectToVoicemail"); return;//from www .ja v a 2 s . co m } final ContentValues values = new ContentValues(1); values.put(Contacts.SEND_TO_VOICEMAIL, value); getContentResolver().update(contactUri, values, null, null); }
From source file:com.grass.caishi.cc.activity.SettingUserActivity.java
/** * onActivityResult// w ww .j av a 2s . com */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ? if (cameraFile != null && cameraFile.exists()) { Log.d("cameraFile" + cameraFile.getAbsolutePath()); // ?uri imageUri = Uri.fromFile(cameraFile); cropImageUri(Uri.fromFile(cameraFile), 300, 300, USERPIC_REQUEST_CODE_CUT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { cropImageUri(selectedImage, 300, 300, USERPIC_REQUEST_CODE_CUT); // Log.d("log","selectedImage"+selectedImage); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {// ? // ? if (data != null) { Bitmap bitmap = data.getParcelableExtra("data"); iv_user_photo.setImageBitmap(bitmap); File file = saveJPGE_After(bitmap, cameraFile); // ???? RequestParams params = new RequestParams(); if (file.exists()) { try { dialog.show(); params.put("logo", file, "image/jpeg"); // params.put("user", // MyApplication.getInstance().getUser()); params.put("type", "logo"); // params.add("uid", uid); HttpRestClient.post(Constant.UPDATE_USER_INFO_DO, params, responseHandler); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(this, "?SD??", Toast.LENGTH_SHORT); } } else { // Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data); } } else if (resultCode == MainActivity.MAIN_MESSAGE_LOGIN_OUT) { setResult(resultCode); finish(); } }
From source file:com.android.contacts.ContactSaveService.java
private void setStarred(Intent intent) { Uri contactUri = intent.getParcelableExtra(EXTRA_CONTACT_URI); boolean value = intent.getBooleanExtra(EXTRA_STARRED_FLAG, false); if (contactUri == null) { Log.e(TAG, "Invalid arguments for setStarred request"); return;/*from w ww . ja va 2 s . com*/ } final ContentValues values = new ContentValues(1); values.put(Contacts.STARRED, value); getContentResolver().update(contactUri, values, null, null); // Undemote the contact if necessary final Cursor c = getContentResolver().query(contactUri, new String[] { Contacts._ID }, null, null, null); if (c == null) { return; } try { if (c.moveToFirst()) { final long id = c.getLong(0); // Don't bother undemoting if this contact is the user's profile. if (id < Profile.MIN_ID) { PinnedPositionsCompat.undemote(getContentResolver(), id); } } } finally { c.close(); } }
From source file:com.appsimobile.appsii.Appsi.java
@Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { Log.d(TAG, "onStartCommand() called with: " + "intent = [" + intent + "], flags = [" + flags + "], startId = [" + startId + "]"); startAppsiService();//from w w w . j a va 2 s.c om // force initialize the home config to make everything a bit smoother // and this makes sure we don't have to wait for it when opening the // sidebar for the first time. // mHomeItemConfigurationHelper String action = intent == null ? null : intent.getAction(); if (ACTION_TRY_PAGE.equals(action)) { HotspotPageEntry entry = intent.getParcelableExtra("entry"); HotspotItem hotspotItem = intent.getParcelableExtra("hotspot"); if (entry != null && hotspotItem != null) { CircularArray<HotspotPageEntry> entries = new CircularArray<>(1); entries.addFirst(entry); openSidebar(hotspotItem, entries, 0, true); } } return Service.START_STICKY; }
From source file:com.citrus.sdk.CitrusClient.java
private <T> void registerReceiver(final Callback<T> callback, IntentFilter intentFilter) { paymentEventReceiver = new BroadcastReceiver() { @Override//from w w w.j ava2s . com public void onReceive(Context context, Intent intent) { unregisterReceiver(this); TransactionResponse transactionResponse = intent .getParcelableExtra(Constants.INTENT_EXTRA_TRANSACTION_RESPONSE); if (transactionResponse != null) { TransactionResponse.TransactionStatus transactionStatus = transactionResponse .getTransactionStatus(); Status status = null; if (transactionStatus != null) { switch (transactionStatus) { case SUCCESSFUL: status = Status.SUCCESSFUL; break; case FAILED: status = Status.FAILED; break; case CANCELLED: status = Status.CANCELLED; break; case PG_REJECTED: status = Status.PG_REJECTED; break; } } if (transactionStatus == TransactionResponse.TransactionStatus.SUCCESSFUL) { sendResponse(callback, transactionResponse); } else { sendError(callback, new CitrusError(transactionResponse.getMessage(), status)); } } } }; LocalBroadcastManager.getInstance(mContext).registerReceiver(paymentEventReceiver, intentFilter); }
From source file:com.gelakinetic.mtgfam.FamiliarActivity.java
/** * Called when another activity returns and this one is displayed. Since the app is fragment based, this is only * called when querying for TTS support, or when returning from a ringtone picker. The preference fragment does * not handle the ringtone result correctly, so it must be caught here. * * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to * identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param data An Intent, which can return result data to the caller (various data can be attached to Intent * "extras")./*ww w .j a v a 2 s. c om*/ */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { mTutorCards.onActivityResult(requestCode, resultCode); /* The ringtone picker in the preference fragment and RoundTimerFragment will send a result here */ if (data != null && data.getExtras() != null) { if (data.getExtras().keySet().contains(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)) { Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (uri != null) { mPreferenceAdapter.setTimerSound(uri.toString()); } } } }
From source file:com.android.contacts.ContactSaveService.java
private void splitContact(Intent intent) { final long rawContactIds[][] = (long[][]) intent.getSerializableExtra(EXTRA_RAW_CONTACT_IDS); final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER); final boolean hardSplit = intent.getBooleanExtra(EXTRA_HARD_SPLIT, false); if (rawContactIds == null) { Log.e(TAG, "Invalid argument for splitContact request"); if (receiver != null) { receiver.send(BAD_ARGUMENTS, new Bundle()); }// w w w. jav a2s . co m return; } final int batchSize = MAX_CONTACTS_PROVIDER_BATCH_SIZE; final ContentResolver resolver = getContentResolver(); 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) { if (!buildSplitTwoContacts(operations, rawContactIds[i], rawContactIds[j], hardSplit)) { if (receiver != null) { receiver.send(CP2_ERROR, new Bundle()); return; } } } } } if (operations.size() > 0 && !applyOperations(resolver, operations)) { if (receiver != null) { receiver.send(CP2_ERROR, new Bundle()); } return; } LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_UNLINK_COMPLETE)); if (receiver != null) { receiver.send(CONTACTS_SPLIT, new Bundle()); } else { showToast(R.string.contactUnlinkedToast); } }
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()); }/*from w w w . j a v a2 s . co 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:com.android.contacts.ContactSaveService.java
private void saveContact(Intent intent) { RawContactDeltaList state = intent.getParcelableExtra(EXTRA_CONTACT_STATE); boolean isProfile = intent.getBooleanExtra(EXTRA_SAVE_IS_PROFILE, false); Bundle updatedPhotos = intent.getParcelableExtra(EXTRA_UPDATED_PHOTOS); if (state == null) { Log.e(TAG, "Invalid arguments for saveContact request"); return;//www . j av a 2s . com } int saveMode = intent.getIntExtra(EXTRA_SAVE_MODE, -1); // Trim any empty fields, and RawContacts, before persisting final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); RawContactModifier.trimEmpty(state, accountTypes); Uri lookupUri = null; final ContentResolver resolver = getContentResolver(); boolean succeeded = false; // Keep track of the id of a newly raw-contact (if any... there can be at most one). long insertedRawContactId = -1; // Attempt to persist changes int tries = 0; while (tries++ < PERSIST_TRIES) { try { // Build operations and try applying final ArrayList<CPOWrapper> diffWrapper = state.buildDiffWrapper(); final ArrayList<ContentProviderOperation> diff = Lists.newArrayList(); for (CPOWrapper cpoWrapper : diffWrapper) { diff.add(cpoWrapper.getOperation()); } if (DEBUG) { Log.v(TAG, "Content Provider Operations:"); for (ContentProviderOperation operation : diff) { Log.v(TAG, operation.toString()); } } int numberProcessed = 0; boolean batchFailed = false; final ContentProviderResult[] results = new ContentProviderResult[diff.size()]; while (numberProcessed < diff.size()) { final int subsetCount = applyDiffSubset(diff, numberProcessed, results, resolver); if (subsetCount == -1) { Log.w(TAG, "Resolver.applyBatch failed in saveContacts"); batchFailed = true; break; } else { numberProcessed += subsetCount; } } if (batchFailed) { // Retry save continue; } final long rawContactId = getRawContactId(state, diffWrapper, results); if (rawContactId == -1) { throw new IllegalStateException("Could not determine RawContact ID after save"); } // We don't have to check to see if the value is still -1. If we reach here, // the previous loop iteration didn't succeed, so any ID that we obtained is bogus. insertedRawContactId = getInsertedRawContactId(diffWrapper, results); if (isProfile) { // Since the profile supports local raw contacts, which may have been completely // removed if all information was removed, we need to do a special query to // get the lookup URI for the profile contact (if it still exists). Cursor c = resolver.query(Profile.CONTENT_URI, new String[] { Contacts._ID, Contacts.LOOKUP_KEY }, null, null, null); if (c == null) { continue; } try { if (c.moveToFirst()) { final long contactId = c.getLong(0); final String lookupKey = c.getString(1); lookupUri = Contacts.getLookupUri(contactId, lookupKey); } } finally { c.close(); } } else { final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); lookupUri = RawContacts.getContactLookupUri(resolver, rawContactUri); } if (lookupUri != null && Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Saved contact. New URI: " + lookupUri); } // We can change this back to false later, if we fail to save the contact photo. succeeded = true; break; } catch (RemoteException e) { // Something went wrong, bail without success FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e); break; } catch (IllegalArgumentException e) { // This is thrown by applyBatch on malformed requests FeedbackHelper.sendFeedback(this, TAG, "Problem persisting user edits", e); showToast(R.string.contactSavedErrorToast); break; } catch (OperationApplicationException e) { // Version consistency failed, re-parent change and try again Log.w(TAG, "Version consistency failed, re-parenting: " + e.toString()); final StringBuilder sb = new StringBuilder(RawContacts._ID + " IN("); boolean first = true; final int count = state.size(); for (int i = 0; i < count; i++) { Long rawContactId = state.getRawContactId(i); if (rawContactId != null && rawContactId != -1) { if (!first) { sb.append(','); } sb.append(rawContactId); first = false; } } sb.append(")"); if (first) { throw new IllegalStateException("Version consistency failed for a new contact", e); } final RawContactDeltaList newState = RawContactDeltaList.fromQuery( isProfile ? RawContactsEntity.PROFILE_CONTENT_URI : RawContactsEntity.CONTENT_URI, resolver, sb.toString(), null, null); state = RawContactDeltaList.mergeAfter(newState, state); // Update the new state to use profile URIs if appropriate. if (isProfile) { for (RawContactDelta delta : state) { delta.setProfileQueryUri(); } } } } // Now save any updated photos. We do this at the end to ensure that // the ContactProvider already knows about newly-created contacts. if (updatedPhotos != null) { for (String key : updatedPhotos.keySet()) { Uri photoUri = updatedPhotos.getParcelable(key); long rawContactId = Long.parseLong(key); // If the raw-contact ID is negative, we are saving a new raw-contact; // replace the bogus ID with the new one that we actually saved the contact at. if (rawContactId < 0) { rawContactId = insertedRawContactId; } // If the save failed, insertedRawContactId will be -1 if (rawContactId < 0 || !saveUpdatedPhoto(rawContactId, photoUri, saveMode)) { succeeded = false; } } } Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); if (callbackIntent != null) { if (succeeded) { // Mark the intent to indicate that the save was successful (even if the lookup URI // is now null). For local contacts or the local profile, it's possible that the // save triggered removal of the contact, so no lookup URI would exist.. callbackIntent.putExtra(EXTRA_SAVE_SUCCEEDED, true); } callbackIntent.setData(lookupUri); deliverCallback(callbackIntent); } }
From source file:com.example.android.wifidirect.WiFiDirectBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { // UI update to indicate wifi p2p status. int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1); if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) { // Wifi Direct mode is enabled activity.setIsWifiP2pEnabled(true); //Wi-Fi direct?? } else {/* w ww . ja v a2 s. c o m*/ activity.setIsWifiP2pEnabled(false); activity.resetData(); } Log.d(WiFiDirectActivity.TAG, "P2P state changed - " + state); } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { // request available peers from the wifi p2p manager. This is an // asynchronous call and the calling activity is notified with a // callback on PeerListListener.onPeersAvailable() //Wi-Fi P2P??PeerListListener.onPeersAvailable()? if (manager != null) { FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_list); manager.requestPeers(channel, (PeerListListener) fragment); } Log.d(WiFiDirectActivity.TAG, "P2P peers changed"); } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { if (manager == null) { return; } NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); if (networkInfo.isConnected()) { // we are connected with the other device, request connection // info to find group owner IP FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity .getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceDetailFragment fragment = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_detail); manager.requestConnectionInfo(channel, fragment); //??onConnectionInfoAvailable } else { // It's a disconnect activity.resetData(); } } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { //???? //DeviceListFragment fragment = (DeviceListFragment) activity.getSupportFragmentManager().findFragmentByTag("devicelistfragment"); FileTransmitFragment fileTransmitfragment = (FileTransmitFragment) activity.getSupportFragmentManager() .findFragmentByTag("android:switcher:" + R.id.pager + ":0"); DeviceListFragment fragment = (DeviceListFragment) fileTransmitfragment.getFragmentManager() .findFragmentById(R.id.frag_list); fragment.updateThisDevice( (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE)); //activity.getSupportFragmentManager().beginTransaction().add(R.id.list_fragment, fragment).commit(); //DeviceDetailFragment fragment2 = (DeviceDetailFragment) fileTransmitfragment.getFragmentManager().findFragmentById(R.id.frag_detail); //fragment2.getrootView().setVisibility(View.VISIBLE); /*Log.d(WiFiDirectActivity.TAG,"Fragment2:"+fragment2); Log.d(WiFiDirectActivity.TAG,"Fragment2.getView():"+fragment2.getView()); Log.d(WiFiDirectActivity.TAG,"Fragment2.getrootView():"+fragment2.getrootView()); Log.d(WiFiDirectActivity.TAG, "Fragment:"+fileTransmitfragment); Log.d(WiFiDirectActivity.TAG, "device:"+(WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));*/ } }