Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

In this page you can find the example usage for android.content Intent getParcelableExtra.

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.android.contacts.SimImportService.java

private ImportTask createTaskForIntent(Intent intent, int startId) {
    final AccountWithDataSet targetAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
    final ArrayList<SimContact> contacts = intent.getParcelableArrayListExtra(EXTRA_SIM_CONTACTS);

    final int subscriptionId = intent.getIntExtra(EXTRA_SIM_SUBSCRIPTION_ID, SimCard.NO_SUBSCRIPTION_ID);
    final SimContactDao dao = SimContactDao.create(this);
    final SimCard sim = dao.getSimBySubscriptionId(subscriptionId);
    if (sim != null) {
        return new ImportTask(sim, contacts, targetAccount, dao, startId);
    } else {/*  w  ww.j  av a  2s  . com*/
        return null;
    }
}

From source file:com.github.dfa.diaspora_android.activity.ShareActivity.java

void handleSendImage(Intent intent) {
    final Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
    if (imageUri != null) {
        // Update UI to reflect text being shared
    }/* w w  w . j  a v a  2s .c  om*/
}

From source file:com.goliathonline.android.kegbot.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);

    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {/*from   w  ww.  j a va2s  .c  o m*/
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_CURRENT;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
        if (localParse) {

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            //mLocalExecutor.execute(context, "cache-drinks.json", new RemoteDrinksHandler());
            //mLocalExecutor.execute(context, "cache-speakers.xml", new RemoteSpeakersHandler());
            //mLocalExecutor.execute(context, "cache-vendors.xml", new RemoteVendorsHandler());

            // Save local parsed version
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        // Always hit remote spreadsheet for any updates
        final long startRemote = System.currentTimeMillis();
        mRemoteExecutor.executeGet(PrefsHelper.getAPIUrl(getBaseContext()) + "/events",
                new RemoteJsonHandler(mRemoteExecutor));
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.infine.android.devoxx.service.RestService.java

@Override
protected void onHandleIntent(Intent intent) {

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);

    // si passage du numero de version
    // final int latestVersion = intent.getIntExtra(EXTRA_LASTEST_VERSION,
    // 1);/*from  w w w.j  ava2  s .  com*/

    if (receiver != null)
        receiver.send(ServiceStatus.STATUS_RUNNING, Bundle.EMPTY);

    // final Context context = this;
    // final SharedPreferences prefs =
    // getSharedPreferences(Prefs.DEVOXX_SCHEDULE_SYNC,
    // Context.MODE_PRIVATE);
    // final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION,
    // VERSION_NONE);

    try {

        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext);
        int scheduleVersion = prefs.getInt(PREFS_SCHEDULE_VERSION, -1);
        int sessionVersion = prefs.getInt(PREFS_SESSION_VERSION, -1);
        int speakerVersion = prefs.getInt(PREFS_SPEAKER_VERSION, -1);

        if (scheduleVersion + sessionVersion + speakerVersion < 0) {
            // on charge les fichiers statiques que la premiere fois
            // ou quand un jeu de donnes schedule ou session est pourri
            // verion = -1
            loadStaticFiles();
        }
        loadStaticRoom();

        // Always hit remote spreadsheet for any updates
        loadRemoteData();

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);
        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Received start id " + startId + ": " + intent);
    if (intent != null) {
        config = (Config) intent.getParcelableExtra("config");
        activity = intent.getStringExtra("activity");
        Log.d(TAG, "Got activity" + activity);

        // Build a Notification required for running service in foreground.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(config.getNotificationTitle());
        builder.setContentText(config.getNotificationText());
        builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
        if (config.getNotificationIcon() != null) {
            builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon()));
            builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(),
                    getPluginResource(config.getLargeNotificationIcon())));
        }/*from  w ww.  jav  a2 s.  c  o m*/
        if (config.getNotificationIconColor() != null) {
            builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor()));
        }

        setClickEvent(builder);

        Notification notification = builder.build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
                | Notification.FLAG_NO_CLEAR;
        startForeground(startId, notification);
    }
    Log.i(TAG, config.toString());
    Log.i(TAG, "- activity: " + activity);

    //We want this service to continue running until it is explicitly stopped
    return START_STICKY;
}

From source file:com.google.android.apps.iosched.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);

    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IOSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {// w  w  w.j a  v  a  2 s.c  om
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_CURRENT;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
        if (localParse) {
            // Load static local data
            mLocalExecutor.execute(R.xml.blocks, new LocalBlocksHandler());
            mLocalExecutor.execute(R.xml.rooms, new LocalRoomsHandler());
            mLocalExecutor.execute(R.xml.tracks, new LocalTracksHandler());
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(R.xml.sessions, new LocalSessionsHandler());

            // Parse values from local cache first, since spreadsheet copy
            // or network might be down.
            mLocalExecutor.execute(context, "cache-sessions.xml", new RemoteSessionsHandler());
            mLocalExecutor.execute(context, "cache-speakers.xml", new RemoteSpeakersHandler());
            mLocalExecutor.execute(context, "cache-vendors.xml", new RemoteVendorsHandler());

            // Save local parsed version
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        // Always hit remote spreadsheet for any updates
        final long startRemote = System.currentTimeMillis();
        mRemoteExecutor.executeGet(WORKSHEETS_URL, new RemoteWorksheetsHandler(mRemoteExecutor));
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:com.firebase.ui.auth.ui.phone.VerifyPhoneNumberFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_PHONE_HINT) {
        if (data != null) {
            Credential cred = data.getParcelableExtra(Credential.EXTRA_KEY);
            if (cred != null) {
                // Hint selector does not always return phone numbers in e164 format.
                // To accommodate either case, we normalize to e164 with best effort
                final String unformattedPhone = cred.getId();
                final String formattedPhone = PhoneNumberUtils
                        .formatPhoneNumberUsingCurrentCountry(unformattedPhone, getContext());
                if (formattedPhone == null) {
                    Log.e(TAG, "Unable to normalize phone number from hint selector:" + unformattedPhone);
                    return;
                }/*w w w. j  av a  2 s . c o  m*/
                final PhoneNumber phoneNumberObj = PhoneNumberUtils.getPhoneNumber(formattedPhone);
                setPhoneNumber(phoneNumberObj);
                setCountryCode(phoneNumberObj);
            }
        }
    }
}

From source file:com.github.pockethub.android.ui.issue.IssuesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == ISSUE_FILTER_EDIT && data != null) {
        IssueFilter newFilter = data.getParcelableExtra(EXTRA_ISSUE_FILTER);
        if (!filter.equals(newFilter)) {
            filter = newFilter;//from ww w.j  a  v a2s.c  o  m
            updateFilterSummary();
            pager.reset();
            refreshWithProgress();
            return;
        }
    }

    if (requestCode == ISSUE_VIEW) {
        notifyDataSetChanged();
        forceRefresh();
        return;
    }

    if (requestCode == ISSUE_CREATE && resultCode == RESULT_OK) {
        Issue created = data.getParcelableExtra(EXTRA_ISSUE);
        forceRefresh();
        startActivityForResult(IssuesViewActivity.createIntent(created, repository), ISSUE_VIEW);
        return;
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.amlcurran.messages.telephony.SmsManagerOutputPort.java

@Override
protected void onHandleIntent(Intent intent) {
    MessagesLog.d(this, intent.toString());
    if (isSendRequest(intent)) {

        InFlightSmsMessage message;//from w w w . ja  v a  2  s.  c  o  m
        if (isFromWear(intent)) {
            message = extractInFlightFromWear(intent);
        } else {
            message = intent.getParcelableExtra(EXTRA_MESSAGE);
        }
        SmsMessage smsMessage = messageRepository.send(message, getContentResolver());
        sendToApi(smsMessage);

    } else if (ACTION_RESEND.equals(intent.getAction())) {

        SingletonManager.getNotifier(this).clearFailureToSendNotification();
        InFlightSmsMessage message = intent.getParcelableExtra(EXTRA_MESSAGE);
        SmsMessage smsMessage = messageRepository.send(message, getContentResolver());
        sendToApi(smsMessage);

    }
}