List of usage examples for android.content Intent getLongExtra
public long getLongExtra(String name, long defaultValue)
From source file:se.erichansander.retrotimer.TimerKlaxon.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { TinyTracelog.trace("4"); // No intent, tell the system not to restart us. if (intent == null) { TinyTracelog.trace("4.e"); stopSelf();//from w w w .jav a 2s . c o m return START_NOT_STICKY; } boolean ring = mPrefs.getBoolean(RetroTimer.PREF_RING_ON_ALARM, true); boolean vibrate = mPrefs.getBoolean(RetroTimer.PREF_VIBRATE_ON_ALARM, true); long timeoutMillis = mPrefs.getLong(RetroTimer.PREF_ALARM_TIMEOUT_MILLIS, 10 * 1000); mAlarmTime = intent.getLongExtra(RetroTimer.ALARM_TIME_EXTRA, 0); // Close dialogs and window shade sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); // Trigger a notification that, when clicked, will dismiss the alarm. Intent notify = new Intent(RetroTimer.ALARM_DISMISS_ACTION); PendingIntent pendingNotify = PendingIntent.getBroadcast(this, 0, notify, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentIntent(pendingNotify) .setDefaults(Notification.DEFAULT_LIGHTS).setOngoing(true) .setSmallIcon(R.drawable.ic_stat_alarm_triggered) .setContentTitle(getString(R.string.notify_triggered_label)) .setContentText(getString(R.string.notify_triggered_text)); /* * Send the notification using the alarm id to easily identify the * correct notification. */ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(RetroTimer.NOTIF_SET_ID); nm.notify(RetroTimer.NOTIF_TRIGGERED_ID, mBuilder.build()); /* * launch UI, explicitly stating that this is not due to user action so * that the current app's notification management is not disturbed */ Intent timerAlert = new Intent(this, TimerAlert.class); timerAlert.putExtra(RetroTimer.ALARM_TIME_EXTRA, mAlarmTime); timerAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); startActivity(timerAlert); play(ring, vibrate); startTimeoutCountdown(timeoutMillis); // Record the initial call state here so that the new alarm has the // newest state. mInitialCallState = mTelephonyManager.getCallState(); // Update the shared state RetroTimer.clearAlarm(this); return START_STICKY; }
From source file:com.android.contacts.activities.ContactDetailActivity.java
/** * M: call back for create or update group in ContactDetailActivity. *///w w w .j a v a2 s . co m @Override public void onServiceCompleted(Intent callbackIntent) { // / M: add for group new feature @{ String action = callbackIntent.getAction(); if (ACTION_UPDATE_COMPLETED.equals(action)) { long mRawContactId = callbackIntent.getLongExtra(ContactSaveService.EXTRA_RAW_CONTACTS_ID, -1); if (mRawContactId <= 0) { LogUtils.i(TAG, "[onServiceCompleted] save contact groups rawcontact id is " + mRawContactId + " Group changes save failed."); return; } } else if (Intent.ACTION_INSERT.equals(action)) { boolean createGroup = callbackIntent.getBooleanExtra(ContactSaveService.CREATE_GROUP_COMP, false); if (createGroup) { ContactDetailFragment detailFragment = mContactDetailLayoutController.getDetailFragment(); String groupName = callbackIntent.getStringExtra(ContactSaveService.EXTRA_NEW_GROUP_NAME); LogUtils.i(TAG, "[onServiceCompleted] create new group's name == " + groupName); detailFragment.setCreateNewGroupName(groupName); } if (callbackIntent.getData() == null) { LogUtils.i(TAG, "[onServiceCompleted] save contact group data is null, Save failed."); return; } } // toast save successful. MtkToast.toast(this, R.string.groupSavedToast); onNewIntent(callbackIntent); }
From source file:com.fenlisproject.elf.core.framework.ElfBinder.java
public static void bindIntentExtra(Object receiver) { Field[] fields = receiver.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true);/*from ww w. ja v a2 s .co m*/ IntentExtra intentExtra = field.getAnnotation(IntentExtra.class); if (intentExtra != null) { try { Intent intent = null; if (receiver instanceof Activity) { intent = ((Activity) receiver).getIntent(); } else if (receiver instanceof Fragment) { intent = ((Fragment) receiver).getActivity().getIntent(); } if (intent != null) { Class<?> type = field.getType(); if (type == Boolean.class || type == boolean.class) { field.set(receiver, intent.getBooleanExtra(intentExtra.value(), false)); } else if (type == Byte.class || type == byte.class) { field.set(receiver, intent.getByteExtra(intentExtra.value(), (byte) 0)); } else if (type == Character.class || type == char.class) { field.set(receiver, intent.getCharExtra(intentExtra.value(), '\u0000')); } else if (type == Double.class || type == double.class) { field.set(receiver, intent.getDoubleExtra(intentExtra.value(), 0.0d)); } else if (type == Float.class || type == float.class) { field.set(receiver, intent.getFloatExtra(intentExtra.value(), 0.0f)); } else if (type == Integer.class || type == int.class) { field.set(receiver, intent.getIntExtra(intentExtra.value(), 0)); } else if (type == Long.class || type == long.class) { field.set(receiver, intent.getLongExtra(intentExtra.value(), 0L)); } else if (type == Short.class || type == short.class) { field.set(receiver, intent.getShortExtra(intentExtra.value(), (short) 0)); } else if (type == String.class) { field.set(receiver, intent.getStringExtra(intentExtra.value())); } else if (type == Boolean[].class || type == boolean[].class) { field.set(receiver, intent.getBooleanArrayExtra(intentExtra.value())); } else if (type == Byte[].class || type == byte[].class) { field.set(receiver, intent.getByteArrayExtra(intentExtra.value())); } else if (type == Character[].class || type == char[].class) { field.set(receiver, intent.getCharArrayExtra(intentExtra.value())); } else if (type == Double[].class || type == double[].class) { field.set(receiver, intent.getDoubleArrayExtra(intentExtra.value())); } else if (type == Float[].class || type == float[].class) { field.set(receiver, intent.getFloatArrayExtra(intentExtra.value())); } else if (type == Integer[].class || type == int[].class) { field.set(receiver, intent.getIntArrayExtra(intentExtra.value())); } else if (type == Long[].class || type == long[].class) { field.set(receiver, intent.getLongArrayExtra(intentExtra.value())); } else if (type == Short[].class || type == short[].class) { field.set(receiver, intent.getShortArrayExtra(intentExtra.value())); } else if (type == String[].class) { field.set(receiver, intent.getStringArrayExtra(intentExtra.value())); } else if (Serializable.class.isAssignableFrom(type)) { field.set(receiver, intent.getSerializableExtra(intentExtra.value())); } else if (type == Bundle.class) { field.set(receiver, intent.getBundleExtra(intentExtra.value())); } } } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
From source file:org.chromium.chrome.browser.download.DownloadManagerService.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (!DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) return;/*w w w . j a v a2 s.c o m*/ final DownloadManager manager = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE); long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); if (downloadId == -1) return; boolean isPendingOMADownload = mOMADownloadHandler.isPendingOMADownload(downloadId); boolean isInOMASharedPrefs = isDownloadIdInOMASharedPrefs(downloadId); if (isPendingOMADownload || isInOMASharedPrefs) { clearPendingOMADownload(downloadId, null); mPendingAutoOpenDownloads.remove(downloadId); } else if (mPendingAutoOpenDownloads.get(downloadId) != null) { Cursor c = manager.query(new DownloadManager.Query().setFilterById(downloadId)); int statusIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS); while (c.moveToNext()) { int status = c.getInt(statusIndex); DownloadInfo info = mPendingAutoOpenDownloads.get(downloadId); switch (status) { case DownloadManager.STATUS_SUCCESSFUL: try { mPendingAutoOpenDownloads.remove(downloadId); if (OMADownloadHandler.OMA_DOWNLOAD_DESCRIPTOR_MIME.equalsIgnoreCase(info.getMimeType())) { mOMADownloadHandler.handleOMADownload(info, downloadId); manager.remove(downloadId); break; } Uri uri = manager.getUriForDownloadedFile(downloadId); Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setDataAndType(uri, manager.getMimeTypeForDownloadedFile(downloadId)); launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(launchIntent); } catch (ActivityNotFoundException e) { Log.w(TAG, "Activity not found."); } break; case DownloadManager.STATUS_FAILED: mPendingAutoOpenDownloads.remove(downloadId); break; default: break; } } } if (mPendingAutoOpenDownloads.size() == 0) { mContext.unregisterReceiver(this); } }
From source file:org.opensilk.music.ui2.LauncherActivity.java
void handleIntent() { Intent intent = getIntent(); final String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { final Uri uri = intent.getData(); final String mimeType = intent.getType(); Timber.i("action=%s, mimeType=%s, uri=%s", action, uri != null ? uri : "null", mimeType); boolean handled = false; if (uri != null && uri.toString().length() > 0) { mMusicService.playFile(uri); handled = true;// w w w .j av a 2s. c o m } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) { long id = intent.getLongExtra("playlistId", -1); if (id < 0) { String idString = intent.getStringExtra("playlist"); if (idString != null) { try { id = Long.parseLong(idString); } catch (NumberFormatException ignored) { } } } if (id >= 0) { mMusicService.playPlaylist(getApplicationContext(), id, false); handled = true; } } if (!handled) { mBus.post(new MakeToast(R.string.err_generic)); } } // intent.setAction(null); }
From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action) || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) || context.getString(R.string.track_paused_broadcast_action).equals(action) || context.getString(R.string.track_resumed_broadcast_action).equals(action) || context.getString(R.string.track_started_broadcast_action).equals(action) || context.getString(R.string.track_stopped_broadcast_action).equals(action) || context.getString(R.string.track_update_broadcast_action).equals(action)) { long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L); update(context, trackId);/* w w w .j av a 2 s.c o m*/ } }
From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case REQUEST_SELECT_CAT: addEntry(data.getLongExtra(CatListDialog.EXTRA_CAT_ID, 0), data.getStringExtra(CatListDialog.EXTRA_CAT_NAME)); break; case REQUEST_ADD_ENTRY: final FragmentManager fm = getFragmentManager(); if (fm != null) { CatListDialog.closeDialog(fm); }//from w w w . j a v a 2 s . c om final EntryListActivity activity = (EntryListActivity) getActivity(); final long entryId = data.getLongExtra(AddEntryActivity.EXTRA_ENTRY_ID, 0); if (activity != null && entryId > 0) { mActivatedItem = entryId; activity.onItemSelected(entryId, data.getStringExtra(AddEntryActivity.EXTRA_ENTRY_CAT), data.getLongExtra(AddEntryActivity.EXTRA_ENTRY_CAT_ID, 0)); } break; case REQUEST_DELETE_ENTRY: final Context context = getContext(); if (context != null) { final long id = data.getLongExtra(EXTRA_ENTRY_ID, 0); new EntryDeleter(context, id).execute(); } break; } } }
From source file:ca.uwaterloo.magic.goodhikes.MapsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_CANCELED) return;/*from w w w . j av a 2 s. c o m*/ if (requestCode == PICK_ROUTE_REQUEST) { if (resultCode == RESULT_OK) { long routeId = data.getLongExtra(RouteEntry._ID, -1); selectedRoute = database.getRoute(routeId); if (!mLoggingService.isTrackingActive()) drawSelectedRoute(); } } }
From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java
/** * Open the playlist editor for the playlist with the given id. *//* w w w. jav a2 s .c om*/ private void editPlaylist(Intent rowData) { Intent launch = new Intent(this, PlaylistActivity.class); launch.putExtra("playlist", rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID)); launch.putExtra("title", rowData.getStringExtra(LibraryAdapter.DATA_TITLE)); startActivity(launch); }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
@Override protected void handleReceivedIntent(Context context, Intent intent) { long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L); if (WallyApplication.getDownloadIDs().containsKey(id)) { WallyApplication.getDownloadIDs().remove(id); updateSaveButton();//from www . j av a2s . c o m if (palette != null && palette.getVibrantSwatch() != null) { startHeartPopoutAnimation(buttonSave, palette.getVibrantSwatch().getBodyTextColor()); } else { startHeartPopoutAnimation(buttonSave, Color.WHITE); } String filename = pageUri.getLastPathSegment(); handleSavedImageData(WallyApplication.getDataProviderInstance().getFilePath(filename)); } }