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:org.openbmap.activities.DialogPreferenceCatalogs.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *///  w ww. j  a va  2 s . c om
@SuppressLint("NewApi")
private void initDownloadManager() {
    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:org.crossconnect.bible.activity.main.ResourceFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    resourceService = ((MainActivity) getActivity()).getResourceService();

    // Prepare the loader.  Either re-connect with an existing one,
    // or start a new one.
    Bundle bundle = new Bundle();
    bundle.putParcelable("BibleText",
            Utils.loadBibleText(getActivity().getSharedPreferences("APP SETTINGS", Context.MODE_PRIVATE)));
    getLoaderManager().initLoader(0, bundle, this);

    // Create an empty adapter we will use to display the loaded data.
    mAdapter = new ResourceListAdapter(getActivity());
    setListAdapter(mAdapter);//from   w  ww.j  a va  2  s.co m

    dm = ((DownloadManager) getActivity().getSystemService("download"));

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                Query query = new Query();
                query.setFilterById(enqueue);
                Cursor c = dm.query(query);
                if (c.moveToFirst()) {
                    int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {

                        String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                    }
                }

                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getActivity()
                        .getSystemService(ns);

                int icon = R.drawable.icon_book_rss;
                CharSequence tickerText = "Resource Download Complete";
                long when = System.currentTimeMillis();

                Notification notification = new Notification(icon, tickerText, when);

                CharSequence contentTitle = "Download Complete";
                CharSequence contentText = "Click to view downloaded resources";

                Intent notificationIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
                notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //uncomment when better
                //                    Intent notificationIntent = new Intent(getActivity(), MusicActivity.class);
                PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, notificationIntent,
                        0);

                notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
                notification.flags |= Notification.FLAG_AUTO_CANCEL;

                int HELLO_ID = 1;

                mNotificationManager.notify(HELLO_ID, notification);
            }
        }
    };

    getActivity().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

}

From source file:net.kjmaster.cookiemom.MainActivity.java

@OnActivityResult(Constants.ASSIGN_SCOUT_REQUEST_CODE)
void onScoutAssign(int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Main.daoSession.getBoothAssignmentsDao().insert(new BoothAssignments(null,
                data.getLongExtra("scout_id", 0), data.getLongExtra("target_id", 0)));

    }/*w  ww.ja v a 2  s  .c  o  m*/
    refreshAll();
}

From source file:at.bitfire.davdroid.DavService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        String action = intent.getAction();
        long id = intent.getLongExtra(EXTRA_DAV_SERVICE_ID, -1);

        switch (action) {
        case ACTION_ACCOUNTS_UPDATED:
            cleanupAccounts();//  w ww. j  av  a2  s .c  o m
            break;
        case ACTION_REFRESH_COLLECTIONS:
            if (runningRefresh.add(id)) {
                new Thread(new RefreshCollections(id)).start();
                for (WeakReference<RefreshingStatusListener> ref : refreshingStatusListeners) {
                    RefreshingStatusListener listener = ref.get();
                    if (listener != null)
                        listener.onDavRefreshStatusChanged(id, true);
                }
            }
            break;
        }
    }

    return START_NOT_STICKY;
}

From source file:org.openbmap.activities.DialogPreferenceMaps.java

/**
 * Initialises download manager for GINGERBREAD and newer
 *//*from ww  w  . ja  va 2 s .c o m*/
@SuppressLint("NewApi")
private void initDownloadManager() {

    mDownloadManager = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);

    mReceiver = new BroadcastReceiver() {
        @SuppressLint("NewApi")
        @Override
        public void onReceive(final Context context, final Intent intent) {
            final String action = intent.getAction();
            if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
                final long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
                final DownloadManager.Query query = new DownloadManager.Query();
                query.setFilterById(downloadId);
                final Cursor c = mDownloadManager.query(query);
                if (c.moveToFirst()) {
                    final int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
                    if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
                        // we're not checking download id here, that is done in handleDownloads
                        final String uriString = c
                                .getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
                        handleDownloads(uriString);
                    } else {
                        final int reason = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
                        Log.e(TAG, "Download failed: " + reason);
                    }
                }
            }
        }
    };

    getContext().registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

From source file:org.sufficientlysecure.keychain.service.PassphraseCacheService.java

/**
 * Register BroadcastReceiver that is unregistered when service is destroyed. This
 * BroadcastReceiver hears on intents with ACTION_PASSPHRASE_CACHE_SERVICE to then timeout
 * specific passphrases in memory.//w  w  w.j a  v a  2  s.c om
 */
private void registerReceiver() {
    if (mIntentReceiver == null) {
        mIntentReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();

                Log.d(TAG, "Received broadcast...");

                if (action.equals(BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE)) {
                    long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
                    timeout(context, keyId);
                }
            }
        };

        IntentFilter filter = new IntentFilter();
        filter.addAction(BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE);
        registerReceiver(mIntentReceiver, filter);
    }
}

From source file:com.llf.android.launcher3.MemoryTracker.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "Received start id " + startId + ": " + intent);

    if (intent != null) {
        if (ACTION_START_TRACKING.equals(intent.getAction())) {
            final int pid = intent.getIntExtra("pid", -1);
            final String name = intent.getStringExtra("name");
            final long start = intent.getLongExtra("start", System.currentTimeMillis());
            startTrackingProcess(pid, name, start);
        }//from   w  w  w.  j a  v  a  2 s  .  co m
    }

    mHandler.sendEmptyMessage(MSG_START);

    return START_STICKY;
}

From source file:com.radioactiveyak.location_best_practices.services.PlaceCheckinService.java

/**
 * {@inheritDoc}//from  www. j  a  v a2 s.c o m
 * Perform a checkin the specified venue. If the checkin fails, add it to the queue and
 * set an alarm to retry.
 * 
 * Query the checkin queue to see if there are pending checkins to be retried.
 */
@Override
protected void onHandleIntent(Intent intent) {
    // Retrieve the details for the checkin to perform.
    String reference = intent.getStringExtra(PlacesConstants.EXTRA_KEY_REFERENCE);
    String id = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID);
    long timeStamp = intent.getLongExtra(PlacesConstants.EXTRA_KEY_TIME_STAMP, 0);

    // Check if we're running in the foreground, if not, check if
    // we have permission to do background updates.
    boolean backgroundAllowed = cm.getBackgroundDataSetting();
    boolean inBackground = sharedPreferences.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true);

    if (reference != null && !backgroundAllowed && inBackground) {
        addToQueue(timeStamp, reference, id);
        return;
    }

    // Check to see if we are connected to a data network.
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver
    // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen
    // for when we connect to a network and start this service to retry the checkins.
    if (!isConnected) {
        // No connection so no point triggering an alarm to retry until we're connected.
        alarmManager.cancel(retryQueuedCheckinsPendingIntent);

        // Enable the Connectivity Changed Receiver to listen for connection to a network
        // so we can commit the pending checkins.
        PackageManager pm = getPackageManager();
        ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class);
        pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

        // Add this checkin to the queue.
        addToQueue(timeStamp, reference, id);
    } else {
        // Execute the checkin. If it fails, add it to the retry queue.
        if (reference != null) {
            if (!checkin(timeStamp, reference, id))
                addToQueue(timeStamp, reference, id);
        }

        // Retry the queued checkins.
        ArrayList<String> successfulCheckins = new ArrayList<String>();
        Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null,
                null, null);
        try {
            // Retry each checkin.
            while (queuedCheckins.moveToNext()) {
                long queuedTimeStamp = queuedCheckins
                        .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP));
                String queuedReference = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE));
                String queuedId = queuedCheckins
                        .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID));
                if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId))
                    successfulCheckins.add(queuedReference);
            }

            // Delete the queued checkins that were successful.
            if (successfulCheckins.size() > 0) {
                StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='"
                        + successfulCheckins.get(0) + "'");
                for (int i = 1; i < successfulCheckins.size(); i++)
                    sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '"
                            + successfulCheckins.get(i) + "'");
                sb.append(")");
                int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI,
                        sb.toString(), null);
                Log.d(TAG, "Deleted: " + deleteCount);
            }

            // If there are still queued checkins then set a non-waking alarm to retry them.
            queuedCheckins.requery();
            if (queuedCheckins.getCount() > 0) {
                long triggerAtTime = System.currentTimeMillis() + PlacesConstants.CHECKIN_RETRY_INTERVAL;
                alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime,
                        retryQueuedCheckinsPendingIntent);
            } else
                alarmManager.cancel(retryQueuedCheckinsPendingIntent);
        } finally {
            queuedCheckins.close();
        }
    }
}

From source file:com.matthewmitchell.wakeifyplus.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    getSupportLoaderManager().restartLoader(0, null, this);
    Log.i("infodb", "GOT RESULT " + requestCode);
    if (requestCode == 1) {
        // If alarm is on, turn off and on again
        Log.i("infodb", "GOT ON " + data.getIntExtra("ON", -1));
        if (data.getIntExtra("ON", 0) == 1) {
            // Alarm is on
            long id = data.getLongExtra("ID", -1);
            Log.i("infodb", "GOT ID " + id);
            if (id != -1)
                AlarmReceiver.scheduleAlarm(this, id, true);
        }//from  w  w w .  ja v a2s.c o m
    }
}

From source file:com.inovex.zabbixmobile.push.NotificationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String status, message, source;
    Long triggerid;//from ww  w.  j  av a2 s  . c  o  m

    if (intent != null) {

        status = intent.getStringExtra("status");
        message = intent.getStringExtra("message");
        triggerid = intent.getLongExtra("triggerid", 0);
        createNotification(status, message, triggerid);

        source = intent.getStringExtra("source");
        // only log if we are running in debug mode
        // http://stackoverflow.com/questions/7022653/how-to-check-programmatically-whether-app-is-running-in-debug-mode-or-not
        if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
            logNotification(status, message, triggerid, source);
        }
    }

    return super.onStartCommand(intent, flags, startId);
}