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:ch.teamuit.android.soundplusplus.LibraryActivity.java

/**
 * Adds songs matching the data from the given intent to the song timelime.
 *
 * @param intent An intent created with// w ww .  j a  va  2 s  . c  om
 * {@link LibraryAdapter#createData(View)}.
 * @param action One of LibraryActivity.ACTION_*
 */
private void pickSongs(Intent intent, int action) {
    long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);

    boolean all = false;
    int mode = action;
    if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) {
        int type = mCurrentAdapter.getMediaType();
        boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID;
        if (mode == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
            mode = ACTION_ENQUEUE;
        } else if (mode == ACTION_PLAY_ALL && notPlayAllAdapter) {
            mode = ACTION_PLAY;
        } else {
            all = true;
        }
    }

    if (id == LibraryAdapter.HEADER_ID)
        all = true; // page header was clicked -> force all mode

    QueryTask query = buildQueryFromIntent(intent, false, (all ? (MediaAdapter) mCurrentAdapter : null));
    query.mode = modeForAction[mode];
    PlaybackService.get(this).addSongs(query);

    mLastActedId = id;

    if (mDefaultAction == ACTION_LAST_USED && mLastAction != action) {
        mLastAction = action;
        updateHeaders();
    }
}

From source file:de.tubs.ibr.dtn.chat.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;
    }/*  w w w .  j a v  a 2  s  . com*/

    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);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(contentTitle);
    builder.setContentText(contentText);
    builder.setSmallIcon(R.drawable.ic_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.setAutoCancel(true);

    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:org.dmfs.tasks.notification.NotificationUpdaterService.java

private void resolveDelayAction(Intent intent) {
    if (!(intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE))) {
        return;/*from  w ww.  j a v  a 2  s .co  m*/
    }
    final String action = intent.getAction();
    final Uri taskUri = intent.getData();
    long due = intent.getLongExtra(EXTRA_TASK_DUE, -1);
    String tz = intent.getStringExtra(EXTRA_TIMEZONE);
    boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false);

    int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.cancel(notificationId);

    if (ACTION_DELAY_1H.equals(action)) {
        Time time = new Time(tz);
        time.set(due);
        time.allDay = false;
        time.hour++;
        time.normalize(true);
        delayTask(taskUri, time);
    } else if (ACTION_DELAY_1D.equals(action)) {
        if (tz == null) {
            tz = "UTC";
        }
        Time time = new Time(tz);
        time.set(due);
        time.allDay = allDay;
        time.monthDay++;
        time.normalize(true);
        delayTask(taskUri, time);
    }

}

From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    setContentView(R.layout.awesome_activity_detail);

    Intent intent = getIntent();
    mApp = (ImApp) getApplication();//from  ww  w . ja  va 2s .  c  o  m

    mChatId = intent.getLongExtra("id", -1);
    mAddress = intent.getStringExtra("address");
    mNickname = intent.getStringExtra("nickname");

    mConvoView = new ConversationView(this);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    //  appBarLayout = (AppBarLayout)findViewById(R.id.appbar);
    mRootLayout = findViewById(R.id.main_content);

    mPrettyTime = new PrettyTime(getCurrentLocale());

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    applyStyleForToolbar();

    /**
    appBarLayout.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        expandToolbar();
    }
    });**/

    processIntent(getIntent());

    collapseToolbar();

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

}

From source file:com.nks.nksmod.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;/* w  ww .  ja v  a  2s  . c  o  m*/

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
        /* } else if (action.equals(DL_KERNEL_ACTION)) {
            KernelInfo.FACTORY.clearUpdateNotif(context);
            KernelInfo.FACTORY.fromIntent(intent).startDownload(context); */
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:org.gnucash.android.ui.account.AccountsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_accounts);

    init();/*from   ww w . j  av  a  2 s  .  c  o  m*/

    mPager = (ViewPager) findViewById(R.id.pager);
    TitlePageIndicator titlePageIndicator = (TitlePageIndicator) findViewById(R.id.titles);

    final Intent intent = getIntent();
    String action = intent.getAction();
    if (action != null && action.equals(Intent.ACTION_INSERT_OR_EDIT)) {
        //enter account creation/edit mode if that was specified
        mPager.setVisibility(View.GONE);
        titlePageIndicator.setVisibility(View.GONE);

        long accountId = intent.getLongExtra(UxArgument.SELECTED_ACCOUNT_ID, 0L);
        if (accountId > 0)
            showEditAccountFragment(accountId);
        else {
            long parentAccountId = intent.getLongExtra(UxArgument.PARENT_ACCOUNT_ID, 0L);
            showAddAccountFragment(parentAccountId);
        }
    } else if (action != null && action.equals(ACTION_VIEW_RECURRING)) {
        mPager.setVisibility(View.GONE);
        titlePageIndicator.setVisibility(View.GONE);
        showRecurringTransactionsFragment();
    } else {
        //show the simple accounts list
        PagerAdapter mPagerAdapter = new AccountViewPagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(mPagerAdapter);
        titlePageIndicator.setViewPager(mPager);

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        int lastTabIndex = preferences.getInt(LAST_OPEN_TAB_INDEX, INDEX_TOP_LEVEL_ACCOUNTS_FRAGMENT);
        mPager.setCurrentItem(lastTabIndex);
    }

}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

/**
 * Creates a context menu for an adapter row.
 *
 * @param menu The menu to create.//from   ww w. j  a v  a2  s .c  o  m
 * @param rowData Data for the adapter row.
 */
public void onCreateContextMenu(ContextMenu menu, Intent rowData) {
    if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) {
        menu.setHeaderTitle(getString(R.string.all_songs));
        menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
    } else {
        int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);

        menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE));

        if (FileUtils.canDispatchIntent(rowData))
            menu.add(0, CTX_MENU_OPEN_EXTERNAL, 0, R.string.open).setIntent(rowData);
        menu.add(0, CTX_MENU_PLAY, 0, R.string.play).setIntent(rowData);
        if (type <= MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        }
        menu.add(0, CTX_MENU_ENQUEUE_AS_NEXT, 0, R.string.enqueue_as_next).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData);
        if (type == MediaUtils.TYPE_PLAYLIST) {
            menu.add(0, CTX_MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData);
        } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) {
            menu.add(0, CTX_MENU_EXPAND, 0, R.string.expand).setIntent(rowData);
        }
        if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
        if (type == MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
            if (PluginUtils.checkPlugins(this))
                menu.add(0, CTX_MENU_PLUGINS, 1, R.string.plugins).setIntent(rowData); // last in order
        }
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
        menu.add(0, CTX_MENU_DELETE, 0, R.string.delete).setIntent(rowData);
    }
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

private void restoreContentFromRecreationKey(String key) {
    String[] args = Util.split(key, separator, 0);
    int recreationVersion;
    try {/*  w  w  w .  j a  v  a 2  s.c o  m*/
        recreationVersion = Integer.parseInt(args[1]);
        if (DEBUG)
            Log.v(LOG_TAG, "RecreationVersion: " + recreationVersion);
    } catch (Exception e) {
        Log.w(LOG_TAG, "Got exception while trying to get recreationVersion for key " + key);
        Log.w(LOG_TAG, "Got exception: " + e);
        // Try using current version instead
        recreationVersion = Util.RECREATION_KEY_VERSION;
    }
    for (int i = 2; i < args.length; i++) {
        String[] subArgs = Util.split(args[i], Util.RK_ATTRIBUTE_SEPARATOR, 1);
        if (ModuleFragment.PAGE_CONTAINER_FRAGMENT.equals(subArgs[0])) {
            addPage(PageContainerFragment.recoverFromRecreationKey(args[i]));
        } else {
            Log.w(LOG_TAG, "restoreContentFromRecreationKey:"
                    + " Only allowed to add PageContainers to MainActivity, you tried to add: " + subArgs[0]);
        }
    }

    if (pages.size() == 0) {// Not allowed to have no fragments
        addPage(PageContainerFragment.newInstance(getString(R.string.page_name_default),
                new Display.StaticTextSettings(getString(R.string.app_name)), false, null, null, null, null));
    }

    // Select page if shortcut used and page is on current orientation:
    Intent intent = getIntent();
    long pageId = intent.getLongExtra(EXTRA_SELECT_PAGE_ID, -1);
    boolean landscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    if (pageId != -1
            && (forceOrientation == -1 || (landscape && forceOrientation == FORCE_ORIENTATION_LANDSCAPE)
                    || (!landscape && forceOrientation == FORCE_ORIENTATION_PORTRAIT))) {
        for (int i = 0; i < pages.size(); i++) {
            if (pages.get(i).getPageId() == pageId) {
                shortcutPage = i;
            }
        }
        if (shortcutPage == -1) {// Could not find page
            if (!intent.getBooleanExtra(EXTRA_RESTARTED_FROM_EDIT_MODE, false))
                Toast.makeText(this, R.string.error_page_not_available, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:eu.alefzero.owncloud.files.services.InstantUploadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null || !intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_DISPLAY_NAME)
            || !intent.hasExtra(KEY_FILE_PATH) || !intent.hasExtra(KEY_FILE_SIZE)
            || !intent.hasExtra(KEY_MIME_TYPE)) {
        Log.w(TAG, "Not all required information was provided, abording");
        return Service.START_NOT_STICKY;
    }//from  w w w.j  a v  a  2s  .co m

    if (mUploaderRunnable == null) {
        mUploaderRunnable = new UploaderRunnable();
    }

    String filename = intent.getStringExtra(KEY_DISPLAY_NAME);
    String filepath = intent.getStringExtra(KEY_FILE_PATH);
    String mimetype = intent.getStringExtra(KEY_MIME_TYPE);
    Account account = intent.getParcelableExtra(KEY_ACCOUNT);
    long filesize = intent.getLongExtra(KEY_FILE_SIZE, -1);

    mUploaderRunnable.addElementToQueue(filename, filepath, mimetype, filesize, account);

    // starting new thread for new download doesnt seems like a good idea
    // maybe some thread pool or single background thread would be better
    Log.d(TAG, "Starting instant upload thread");
    new Thread(mUploaderRunnable).start();

    return Service.START_STICKY;
}

From source file:com.piusvelte.mosaic.android.MosaicMap.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    getActivity();//from   www  .  java 2s  . c o  m
    if ((requestCode == REQUEST_INSERT_MESSAGE) && (resultCode == Activity.RESULT_OK)) {
        try {
            iLocationService.insertMessage(data.getStringExtra(Mosaic.EXTRA_TITLE),
                    data.getStringExtra(Mosaic.EXTRA_BODY), data.getIntExtra(Mosaic.EXTRA_LATITUDE, 0),
                    data.getIntExtra(Mosaic.EXTRA_LONGITUDE, 0), data.getIntExtra(Mosaic.EXTRA_RADIUS, 0),
                    data.getLongExtra(Mosaic.EXTRA_EXPIRY, Mosaic.NEVER_EXPIRES));
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        getActivity();
        if ((requestCode == REQUEST_UPDATE_MESSAGE) && (resultCode == Activity.RESULT_OK)) {
            if (data.hasExtra(Mosaic.EXTRA_TITLE)) {
                try {
                    iLocationService.updateMessage(data.getLongExtra(Mosaic.EXTRA_ID, Mosaic.INVALID_ID),
                            data.getStringExtra(Mosaic.EXTRA_TITLE), data.getStringExtra(Mosaic.EXTRA_BODY),
                            data.getIntExtra(Mosaic.EXTRA_RADIUS, 0),
                            data.getLongExtra(Mosaic.EXTRA_EXPIRY, Mosaic.NEVER_EXPIRES));
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else {
                Long id = data.getLongExtra(Mosaic.EXTRA_ID, Mosaic.INVALID_ID);
                if (markers.containsKey(id)) {
                    messages.remove(markers.get(id).getId());
                    markers.remove(id).remove();
                }
                if (polygons.containsKey(id))
                    polygons.remove(id).remove();
                try {
                    iLocationService.removeMessage(id);
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } else {
            if ((requestCode == REQUEST_VIEW_MESSAGE) && (resultCode == Activity.RESULT_OK)) {
                try {
                    iLocationService.reportMessage(data.getLongExtra(Mosaic.EXTRA_ID, Mosaic.INVALID_ID));
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}