List of usage examples for android.content Intent getLongExtra
public long getLongExtra(String name, long defaultValue)
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java
/** * Loads action item from the given intent * * @param intent/*from ww w . j a v a 2 s. com*/ */ @SuppressWarnings("nls") protected void loadItem(Intent intent) { if (model != null) { // came from bundle isNewTask = (model.getValue(Task.TITLE).length() == 0); return; } long idParam = intent.getLongExtra(TaskEditFragment.TOKEN_ID, -1L); database.openForReading(); if (idParam > -1L) { model = taskService.fetchById(idParam, Task.PROPERTIES); if (model == null) { this.onBackPressed(); } } // not found by id or was never passed an id if (model == null) { String valuesAsString = intent.getStringExtra(TaskEditFragment.TOKEN_VALUES); ContentValues values = null; try { if (valuesAsString != null) values = AndroidUtilities.contentValuesFromSerializedString(valuesAsString); } catch (Exception e) { // oops, can't serialize } model = TaskService.createWithValues(values, null); } if (model == null) { exceptionService.reportError("task-edit-no-task", new NullPointerException("model")); onBackPressed(); return; } // clear notification Notifications.cancelNotifications(model.getId()); }
From source file:com.socialdisasters.other.service.ChatService.java
@SuppressWarnings("deprecation") private void showNotification(Intent intent) { int defaults = 0; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("vibrateOnMessage", true)) { defaults |= Notification.DEFAULT_VIBRATE; }//www. j av a 2 s.co m Long buddyId = intent.getLongExtra(EXTRA_BUDDY_ID, -1L); String displayName = intent.getStringExtra(EXTRA_DISPLAY_NAME); String textBody = intent.getStringExtra(EXTRA_TEXT_BODY); CharSequence tickerText = getString(R.string.new_message_from) + " " + displayName; CharSequence contentTitle = getString(R.string.new_message); CharSequence contentText = displayName + ":\n" + textBody; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // forward intent to the activity intent.setClass(this, MainActivity.class); // Adds the intent to the main view stackBuilder.addNextIntent(intent); // Gets a PendingIntent containing the entire back stack PendingIntent contentIntent = stackBuilder.getPendingIntent(buddyId.intValue(), PendingIntent.FLAG_UPDATE_CURRENT); // create a reply intent String replyLabel = getResources().getString(R.string.reply_label); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build(); Intent replyIntent = new Intent(this, ReplyActivity.class); replyIntent.putExtra(EXTRA_BUDDY_ID, buddyId); PendingIntent replyPendingIntent = PendingIntent.getActivity(this, buddyId.intValue(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply, getString(R.string.reply_label), replyPendingIntent).addRemoteInput(remoteInput).build(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(contentTitle); builder.setContentText(contentText); builder.setSmallIcon(R.drawable.ic_stat_message); builder.setTicker(tickerText); builder.setDefaults(defaults); builder.setWhen(System.currentTimeMillis()); builder.setContentIntent(contentIntent); builder.setLights(0xffff0000, 300, 1000); builder.setSound( Uri.parse(prefs.getString("ringtoneOnMessage", "content://settings/system/notification_sound"))); builder.extend(new WearableExtender().addAction(action)); builder.setAutoCancel(false); Notification notification = builder.getNotification(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(buddyId.toString(), MESSAGE_NOTIFICATION, notification); if (prefs.getBoolean("ttsWhenOnHeadset", false)) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am.isBluetoothA2dpOn() || am.isWiredHeadsetOn()) { // speak the notification Intent tts_intent = new Intent(this, TTSService.class); tts_intent.setAction(TTSService.INTENT_SPEAK); tts_intent.putExtra("speechText", tickerText + ": " + textBody); startService(tts_intent); } } }
From source file:com.makotojava.android.debate.PolicySpeechFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // /* ww w.j av a 2s . c o m*/ if (resultCode == Activity.RESULT_OK) { long millisUntilFinished = data.getLongExtra(TimePickerFragment.RESULT_MILLIS, 0); Log.d(TAG, "Returned from TimePickerDialog... millis => " + millisUntilFinished); if (requestCode == RQID_SPEECHTIMER) { Log.d(TAG, "Speech Timer"); _speechTimer.setMillisUntilFinished(millisUntilFinished); ; } else if (requestCode == RQID_CROSSEXTIMER) { Log.d(TAG, "CrossEx Timer"); _crossexTimer.setMillisUntilFinished(millisUntilFinished); } else if (requestCode == RQID_AFFPREPTIMER) { Log.d(TAG, "Aff Prep Timer"); getAffirmativePrepTimer().setMillisUntilFinished(millisUntilFinished); getPolicySpeechSingleton().setAffirmativePrepRemainingTime(millisUntilFinished); } else if (requestCode == RQID_NEGPREPTIMER) { Log.d(TAG, "Neg Prep Timer"); getNegativePrepTimer().setMillisUntilFinished(millisUntilFinished); getPolicySpeechSingleton().setNegativePrepRemainingTime(millisUntilFinished); } manageState(); } }
From source file:com.klinker.android.twitter.activities.tweet_viewer.TweetPager.java
public void getFromIntent() { Intent from = getIntent(); name = from.getStringExtra("name"); screenName = from.getStringExtra("screenname"); tweet = from.getStringExtra("tweet"); time = from.getLongExtra("time", 0); retweeter = from.getStringExtra("retweeter"); webpage = from.getStringExtra("webpage"); tweetId = from.getLongExtra("tweetid", 0); picture = from.getBooleanExtra("picture", false); proPic = from.getStringExtra("proPic"); secondAcc = from.getBooleanExtra("second_account", false); animatedGif = from.getStringExtra("animated_gif"); try {// ww w .j a v a 2s . c o m users = from.getStringExtra("users").split(" "); } catch (Exception e) { users = null; } try { hashtags = from.getStringExtra("hashtags").split(" "); } catch (Exception e) { hashtags = null; } try { linkString = from.getStringExtra("other_links"); otherLinks = linkString.split(" "); } catch (Exception e) { otherLinks = null; } if (screenName.equals(settings.myScreenName)) { isMyTweet = true; } else if (screenName.equals(retweeter)) { isMyRetweet = true; } tweet = restoreLinks(tweet); if (hashtags != null) { // we will add them to the auto complete new Thread(new Runnable() { @Override public void run() { ArrayList<String> tags = new ArrayList<String>(); if (hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { tags.add("#" + s); } } } HashtagDataSource source = HashtagDataSource.getInstance(context); for (String s : tags) { Log.v("talon_hashtag", "trend: " + s); if (s.contains("#")) { // we want to add it to the auto complete Log.v("talon_hashtag", "adding: " + s); source.deleteTag(s); source.createTag(s); } } } }).start(); } }
From source file:com.klinker.android.twitter.ui.tweet_viewer.TweetPager.java
public void getFromIntent() { Intent from = getIntent(); name = from.getStringExtra("name"); screenName = from.getStringExtra("screenname"); tweet = from.getStringExtra("tweet"); time = from.getLongExtra("time", 0); retweeter = from.getStringExtra("retweeter"); webpage = from.getStringExtra("webpage"); tweetId = from.getLongExtra("tweetid", 0); picture = from.getBooleanExtra("picture", false); proPic = from.getStringExtra("proPic"); try {/*from www. j av a2 s . c om*/ users = from.getStringExtra("users").split(" "); } catch (Exception e) { users = null; } try { hashtags = from.getStringExtra("hashtags").split(" "); } catch (Exception e) { hashtags = null; } try { linkString = from.getStringExtra("other_links"); otherLinks = linkString.split(" "); } catch (Exception e) { otherLinks = null; } if (screenName.equals(settings.myScreenName)) { isMyTweet = true; } else if (screenName.equals(retweeter)) { isMyRetweet = true; } tweet = restoreLinks(tweet); if (hashtags != null) { // we will add them to the auto complete new Thread(new Runnable() { @Override public void run() { ArrayList<String> tags = new ArrayList<String>(); if (hashtags != null) { for (String s : hashtags) { if (!s.equals("")) { tags.add("#" + s); } } } HashtagDataSource source = HashtagDataSource.getInstance(context); for (String s : tags) { Log.v("talon_hashtag", "trend: " + s); if (s.contains("#")) { // we want to add it to the auto complete Log.v("talon_hashtag", "adding: " + s); source.deleteTag(s); source.createTag(s); } } } }).start(); } }
From source file:me.myatminsoe.myansms.MessageListActivity.java
/** * Parse data pushed by {@link Intent}.//from w w w. j a va 2s . co m * * @param intent {@link Intent} */ private void parseIntent(final Intent intent) { if (intent == null) { return; } needContactUpdate = true; uri = intent.getData(); if (uri != null) { if (!uri.toString().startsWith(URI)) { uri = Uri.parse(URI + uri.getLastPathSegment()); } } else { final long tid = intent.getLongExtra("thread_id", -1L); uri = Uri.parse(URI + tid); if (tid < 0L) { try { startActivity(ConversationListActivity.getComposeIntent(this, null, false)); } catch (ActivityNotFoundException e) { Log.e(TAG, "activity not found", e); Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show(); } finish(); return; } } int threadId; try { threadId = Integer.parseInt(uri.getLastPathSegment()); } catch (NumberFormatException e) { Log.e(TAG, "unable to parse thread id: ", e); Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show(); finish(); return; } Conversation c; try { c = Conversation.getConversation(this, threadId, true); threadId = c.getThreadId(); // force a NPE :x } catch (NullPointerException e) { Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show(); finish(); return; } conv = c; final Contact contact = c.getContact(); try { contact.update(this, false, true); } catch (NullPointerException e) { Log.e(TAG, "updating contact failed", e); } boolean showKeyboard = intent.getBooleanExtra("showKeyboard", false); final ListView lv = getListView(); lv.setStackFromBottom(true); MessageAdapter adapter = new MessageAdapter(this, uri); setListAdapter(adapter); String displayName = contact.getDisplayName(); setTitle(displayName); String number = contact.getNumber(); if (displayName.equals(number)) { getSupportActionBar().setSubtitle(null); } else { getSupportActionBar().setSubtitle(number); } final String body = intent.getStringExtra(Intent.EXTRA_TEXT); if (!TextUtils.isEmpty(body)) { etText.setText(body); showKeyboard = true; } if (showKeyboard) { etText.requestFocus(); } setRead(); }
From source file:net.lacolaco.smileessence.activity.MainActivity.java
private void receiveOAuth(int requestCode, int resultCode, Intent data) { if (resultCode != RESULT_OK) { Logger.error(requestCode); Notificator.publish(this, R.string.notice_error_authenticate); finish();//from w w w .j a v a 2s . co m } else { Account account = new Account(data.getStringExtra(OAuthSession.KEY_TOKEN), data.getStringExtra(OAuthSession.KEY_TOKEN_SECRET), data.getLongExtra(OAuthSession.KEY_USER_ID, -1L), data.getStringExtra(OAuthSession.KEY_SCREEN_NAME)); account.save(); setCurrentAccount(account); setLastUsedAccountID(account); startMainLogic(); } }
From source file:com.tonyodev.fetch.FetchService.java
private void processAction(final Intent intent) { if (intent == null) { return;//www . j a va2 s . c om } if (!executor.isShutdown()) { executor.execute(new Runnable() { @Override public void run() { final long id = intent.getLongExtra(EXTRA_ID, DEFAULT_EMPTY_VALUE); switch (intent.getIntExtra(ACTION_TYPE, DEFAULT_EMPTY_VALUE)) { case ACTION_PAUSE: { pause(id); break; } case ACTION_REMOVE: { remove(id); break; } case ACTION_RESUME: { resume(id); break; } case ACTION_ENQUEUE: { String url = intent.getStringExtra(EXTRA_URL); String filePath = intent.getStringExtra(EXTRA_FILE_PATH); ArrayList<Bundle> headers = intent.getParcelableArrayListExtra(EXTRA_HEADERS); int priority = intent.getIntExtra(EXTRA_PRIORITY, PRIORITY_NORMAL); enqueue(url, filePath, headers, priority); break; } case ACTION_NETWORK: { int network = intent.getIntExtra(EXTRA_NETWORK_ID, NETWORK_ALL); setAllowedNetwork(network); break; } case ACTION_LOGGING: { boolean enabled = intent.getBooleanExtra(EXTRA_LOGGING_ID, true); setLoggingEnabled(enabled); break; } case ACTION_PROCESS_PENDING: { startDownload(); break; } case ACTION_QUERY: { long queryId = intent.getLongExtra(EXTRA_QUERY_ID, DEFAULT_EMPTY_VALUE); int queryType = intent.getIntExtra(EXTRA_QUERY_TYPE, QUERY_ALL); int status = intent.getIntExtra(EXTRA_STATUS, DEFAULT_EMPTY_VALUE); query(queryType, queryId, id, status); break; } case ACTION_PRIORITY: { int priority = intent.getIntExtra(EXTRA_PRIORITY, PRIORITY_NORMAL); setRequestPriority(id, priority); break; } case ACTION_RETRY: { retry(id); break; } case ACTION_REMOVE_ALL: { removeAll(); break; } case ACTION_CONCURRENT_DOWNLOADS_LIMIT: { int limit = intent.getIntExtra(EXTRA_CONCURRENT_DOWNLOADS_LIMIT, DEFAULT_DOWNLOADS_LIMIT); setDownloadsLimit(limit); break; } case ACTION_UPDATE_REQUEST_URL: { String url = intent.getStringExtra(EXTRA_URL); updateRequestUrl(id, url); break; } default: { startDownload(); break; } } } }); } }
From source file:io.plaidapp.ui.HomeActivity.java
@Override public void onActivityReenter(int resultCode, Intent data) { if (data == null || resultCode != RESULT_OK || !data.hasExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID)) return;/*from w w w . j a v a 2 s. c o m*/ // When reentering, if the shared element is no longer on screen (e.g. after an // orientation change) then scroll it into view. final long sharedShotId = data.getLongExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID, -1L); if (sharedShotId != -1L // returning from a shot && adapter.getDataItemCount() > 0 // grid populated && grid.findViewHolderForItemId(sharedShotId) == null) { // view not attached final int position = adapter.getItemPosition(sharedShotId); if (position == RecyclerView.NO_POSITION) return; // delay the transition until our shared element is on-screen i.e. has been laid out postponeEnterTransition(); grid.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) { grid.removeOnLayoutChangeListener(this); startPostponedEnterTransition(); } }); grid.scrollToPosition(position); toolbar.setTranslationZ(-1f); } }
From source file:com.bt.download.android.gui.activities.AudioPlayerActivity.java
private long parseIdFromIntent(Intent intent, String longKey, String stringKey, long defaultId) { long id = intent.getLongExtra(longKey, -1); if (id < 0) { String idString = intent.getStringExtra(stringKey); if (idString != null) { try { id = Long.parseLong(idString); } catch (NumberFormatException e) { // ignore }/*w w w . j a v a2s .c om*/ } } return id; }