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:com.gerolab.sdksample.SleepStateReceiver.java

public void onReceive(Context context, Intent intent) {
    long startTime = intent.getLongExtra(GeroAccelerometerService.EXTRA_SLEEP_START_TIME, 0);
    long endTime = intent.getLongExtra(GeroAccelerometerService.EXTRA_SLEEP_END_TIME, 0);
    int deltaMinutes = (int) ((endTime - startTime) / 60);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(android.R.drawable.stat_notify_sync)
            .setContentTitle(context.getString(R.string.label_sleep_notification)).setContentText(
                    String.format(context.getString(R.string.label_sleep_notification_content, deltaMinutes)));
    Intent resultIntent = new Intent(context, LoginActivity.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setDefaults(Notification.DEFAULT_ALL);
    mBuilder.setAutoCancel(true);//  w  w  w  . j a va2s  . c  o m
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:pl.ipebk.tabi.presentation.ui.details.DetailsCategoryActivity.java

@Override
protected void loadData() {
    Intent intent = getIntent();
    long placeId = intent.getLongExtra(PARAM_PLACE_ID, 0L);
    String searchedPlate = intent.getStringExtra(PARAM_SEARCHED_PLATE);
    int position = intent.getIntExtra(PARAM_ADAPTER_POSITION, -1);

    DetailsFragment fragment = DetailsFragment.newInstance(placeId, searchedPlate, PlaceListItemType.SEARCH,
            SearchType.LICENSE_PLATE, position);
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.content_container, fragment);
    ft.commit();/*from  w ww.  ja v  a2 s .  c  om*/
}

From source file:org.kontalk.ui.GroupInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.group_info_screen);

    setupToolbar(true, false);//  w w  w.j  av a2 s.c om

    if (savedInstanceState == null) {
        Intent i = getIntent();
        long threadId = i.getLongExtra("conversation", Messages.NO_THREAD);
        Fragment f = GroupInfoFragment.newInstance(threadId);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment, f).commit();
    }
}

From source file:org.mozilla.focus.broadcastreceiver.DownloadBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final long downloadReference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
    displaySnackbar(context, downloadReference, downloadManager);
}

From source file:com.bexkat.feedlib.ItemDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.Theme_Sherlock);/*from   w  w w .  j a v a  2 s  . c  o  m*/

    Bundle b = new Bundle();

    Intent intent = getIntent();
    long id = intent.getLongExtra(ItemTable._ID, 0);

    ItemTable table = new ItemTable(this);
    EnclosureTable et = new EnclosureTable(this);
    Item item = table.getItem(id);
    List<Enclosure> encs = et.getEnclosures(item);

    b.putString("title", item.getTitle());
    b.putString("pubDate", item.getPubdate().toString());
    b.putString("content", item.getContent());
    b.putBoolean("fav", item.isFavorite());
    b.putLong("id", id);
    try {
        b.putString("uri", item.getLink().toURI().toString());
    } catch (URISyntaxException e) {
        try {
            b.putString("uri", encs.get(0).getURL().toURI().toString());
        } catch (URISyntaxException e1) {
            Toast.makeText(this, "Article can't be loaded", Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    Fragment f = getSupportFragmentManager().findFragmentById(android.R.id.content);
    if (f == null) {
        f = ItemDetailFragment.newInstance(b);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(android.R.id.content, f).commit();
    }
}

From source file:com.rappsantiago.weighttracker.progress.AddEditProgressActivity.java

@Override
protected void setup(Intent intent) {
    if (null != intent) {
        mExistingProgressId = intent.getLongExtra(EXTRA_EXISTING_PROGRESS_ID, -1L);
    }/*www.  ja  v a2s . c o m*/
}

From source file:com.flowzr.budget.holo.activity.EntityListFragment.java

public void createTransactionFromTemplate(Intent data) {
    long templateId = data.getLongExtra(SelectTemplateActivity.TEMPATE_ID, -1);
    int multiplier = data.getIntExtra(SelectTemplateActivity.MULTIPLIER, 1);
    boolean edit = data.getBooleanExtra(SelectTemplateActivity.EDIT_AFTER_CREATION, false);
    if (templateId > 0) {
        long id = duplicateTransaction(templateId, multiplier);
        Transaction t = db.getTransaction(id);
        if (t.fromAmount == 0 || edit) {
            new BlotterOperations(new BlotterFragment(), db, id).asNewFromTemplate().editTransaction();
        }/*from w  ww .  j  av  a2  s  . com*/
    }
}

From source file:com.weidian.blockcanary.StackInfoCatcher.java

public StackInfoCatcher(Context context) {
    this.mContext = context;
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override//from   w w  w.j  av  a  2s  .  c  om
        public void onReceive(Context context, Intent intent) {
            long endTime = intent.getLongExtra(LogPrinter.EXTRA_FINISH_TIME, 0);
            long startTime = intent.getLongExtra(LogPrinter.EXTRA_START_TIME, 0);
            StackTraceInfo info = getInfoByTime(endTime, startTime);
            if (null != info) {
                Log.e(TAG, "find block line");
                //info.mANRError.printStackTrace();
                Log.e(TAG, info.mLog);
            } else {
                Log.e(TAG, "no block line find");
            }
        }
    };
    manager.registerReceiver(mBroadcastReceiver, new IntentFilter(LogPrinter.ACTION_BLOCK));
}

From source file:com.liferay.alerts.receiver.WearableVoteReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    long alertId = intent.getLongExtra(EXTRA_ALERT_ID, 0);

    PollsQuestion question = (PollsQuestion) intent.getSerializableExtra(EXTRA_QUESTION);

    int questionId = question.getQuestionId();

    Bundle input = RemoteInput.getResultsFromIntent(intent);
    String description = input.getCharSequence(EXTRA_CHOICE).toString();

    List<PollsChoice> choices = question.getChoices();
    int choiceId = getChoiceId(choices, description);

    VoteCallback callback = new VoteCallback(context, alertId, questionId);
    callback.vote(choiceId);//  w  ww .  ja v a2  s .  c om
}

From source file:com.android.calendarDemo.alerts.DismissAlarmsService.java

@Override
public void onHandleIntent(Intent intent) {

    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);

    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;/*from w w  w  .  j  a va  2s .c o  m*/

    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID
                + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0) {
        selection = buildMultipleEventsQuery(eventIds);
    } else {
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }

    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);

    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }

    if (showEvent) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);

        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i)
                .startActivities();
    }

    // Stop this service
    stopSelf();
}