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.auth0.lock.receiver.AuthenticationReceiver.java

@Override
public final void onReceive(Context context, Intent intent) {
    if (Lock.CANCEL_ACTION.equals(intent.getAction())) {
        onCancel();/*from   w w  w.  j av  a  2s.  c o m*/
    }
    if (Lock.CHANGE_PASSWORD_ACTION.equals(intent.getAction())) {
        onChangePassword();
    }
    if (Lock.AUTHENTICATION_ACTION.equals(intent.getAction())) {
        UserProfile profile = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER);
        Token token = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER);
        if (token == null && profile == null) {
            onSignUp();
        } else {
            onAuthentication(profile, token);
        }
    }
}

From source file:com.lanet.lanetfit.mapservices.UtilityService.java

/**
 * Called when the location has been updated
 *//* w w  w  . j  ava2  s. c  om*/
private void locationUpdated(Intent intent) {
    Log.v(TAG, ACTION_LOCATION_UPDATED);

    // Extra new location
    Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);

    if (location != null) {
        LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude());

        // Store in a local preference as well
        Utils.storeLocation(this, latLngLocation);

        // Send a local broadcast so if an Activity is open it can respond
        // to the updated location
        Log.d(TAG, "locationUpdated() called with: " + "intent = [" + location.getAccuracy() + "]"
                + location.toString());
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}

From source file:org.ietf.ietfsched.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (debbug)// ww w  . j  a  v  a  2s .  c o m
        Log.d(TAG, "Receiver is = " + receiver);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);
    final Context context = this;
    final SharedPreferences prefs = getSharedPreferences(Prefs.IETFSCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);
    //      final int lastLength = prefs.getInt(Prefs.LAST_LENGTH, VERSION_NONE);
    final String lastEtag = prefs.getString(Prefs.LAST_ETAG, "");
    //      final long startLocal = System.currentTimeMillis();

    //boolean localParse = localVersion < VERSION_CURRENT;
    boolean localParse = false;
    Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
    boolean remoteParse = true;
    //      int remoteLength = -1;
    String remoteEtag = "";

    try {
        String htmlURL = BASE_URL + "agenda.csv";
        if (debbug)
            Log.d(TAG, "HEAD " + htmlURL);
        remoteEtag = mRemoteExecutor.executeHead(htmlURL);
        if (debbug)
            Log.d(TAG, "HEAD " + htmlURL + " " + remoteEtag);
        if (remoteEtag == null) {
            Log.d(TAG, "Error connection, cannot retrieve any information from" + htmlURL);
            remoteParse = false;
        } else {
            remoteParse = !remoteEtag.equals(lastEtag);
        }
    } catch (Exception e) {
        remoteParse = false;
        e.printStackTrace();
    }

    // HACK FOR TESTS PURPOSES. TO REMOVE 
    //      Log.w(TAG, "For tests purposes, only the local parsing is activated");
    //      remoteParse = false;
    //      localParse = true;
    // HACK FIN.   

    if (!remoteParse && !localParse) {
        Log.d(TAG, "Already synchronized");
        if (receiver != null)
            receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        return;
    }

    if (remoteParse) {
        String csvURL = BASE_URL + "agenda.csv";
        try {
            if (debbug)
                Log.d(TAG, csvURL);
            InputStream agenda = mRemoteExecutor.executeGet(csvURL);
            mLocalExecutor.execute(agenda);
            prefs.edit().putString(Prefs.LAST_ETAG, remoteEtag).commit();
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
            localParse = false;
            Log.d(TAG, "remote sync finished");
            if (receiver != null)
                receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        } catch (Exception e) {
            Log.e(TAG, "Error HTTP request " + csvURL, e);
            if (!localParse) {
                final Bundle bundle = new Bundle();
                bundle.putString(Intent.EXTRA_TEXT, "Connection error. No updates.");
                if (receiver != null) {
                    receiver.send(STATUS_ERROR, bundle);
                }
            }
        }
    }

    if (localParse) {
        try {
            mLocalExecutor.execute(context, "agenda-83.csv");
            Log.d(TAG, "local sync finished");
            prefs.edit().putInt(Prefs.LOCAL_VERSION, VERSION_CURRENT).commit();
            if (receiver != null)
                receiver.send(STATUS_FINISHED, Bundle.EMPTY);
        } catch (Exception e) {
            e.printStackTrace();
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            if (receiver != null) {
                receiver.send(STATUS_ERROR, bundle);
            }
        }
    }
}

From source file:com.kuacm.expo2013.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 a2  s  . 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) {
            // 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.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java

private Fragment getRootFragment() {
    final Intent intent = getIntent();
    final Fragment rootFragment;

    if (intent.hasExtra(EXTRA_ALBUM)) {
        final Album album = intent.getParcelableExtra(EXTRA_ALBUM);

        rootFragment = new SongsFragment().init(album);
    } else if (intent.hasExtra(EXTRA_ARTIST)) {
        final Artist artist = intent.getParcelableExtra(EXTRA_ARTIST);
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mApp);

        if (settings.getBoolean(LibraryFragment.PREFERENCE_ALBUM_LIBRARY, true)) {
            rootFragment = new AlbumsGridFragment(artist);
        } else {//from w ww. j a  v  a 2 s  .co  m
            rootFragment = new AlbumsFragment(artist);
        }
    } else if (intent.hasExtra(EXTRA_FOLDER)) {
        final String folder = intent.getStringExtra(EXTRA_FOLDER);

        rootFragment = new FSFragment().init(folder);
    } else if (intent.hasExtra(EXTRA_STREAM)) {
        rootFragment = new StreamsFragment();
    } else {
        throw new IllegalStateException(debugIntent(intent));
    }

    return rootFragment;
}

From source file:com.zion.htf.ui.DonateActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (Activity.RESULT_OK == resultCode) {
        PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
        if (null != confirm) {
            try {
                if (BuildConfig.DEBUG)
                    Log.i(DonateActivity.TAG, confirm.toJSONObject().toString(4));

                // TODO: send 'confirm' to your server for verification.
                // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                // for more details.
            } catch (JSONException e) {
                Log.e(DonateActivity.TAG, "an extremely unlikely failure occurred: ", e);
            }//from  w  w  w. j  ava  2 s .co  m
        }
    } else if (Activity.RESULT_CANCELED == resultCode) {
        if (BuildConfig.DEBUG)
            Log.i(DonateActivity.TAG, "The user canceled.");
    } else if (PaymentActivity.RESULT_PAYMENT_INVALID == resultCode) {
        Log.e(DonateActivity.TAG, "An invalid payment was submitted. Please see the docs.");
    }
}

From source file:com.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (networkInfo.isConnected()) {
            /**/* w  w  w .  ja  va2 s  .  c om*/
             * WiFi is connected, get its broadcast 
             * address and start the discovery process
             * repeated at a fixed time interval
             */
            wifiBroadcastAddress = getWiFiBroadcastAddress(context);
            startAlarmRepeater(context);
        } else {
            wifiBroadcastAddress = null;
        }
    } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
        NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI && !networkInfo.isConnected()) {
            /**
             * WiFi is disconnected, stop the discovery
             * process repeating, it would be a waste of resources
             */
            wifiBroadcastAddress = null;
            stopAlarmRepeater(context);
        }
    } else if (intent.getAction().equals(context.getResources().getString(R.string.broadcast_startdiscovery))
            || intent.getAction()
                    .equals(context.getResources().getString(R.string.broadcast_cleanhostcollection))) {

        boolean startService = true;
        /**
         * Calls the DiscoverServerService asking to do a discovery
         * or a clean host collection by simply forwarding the received action
         */
        Intent service = new Intent(context, DiscoverServerService.class);
        service.setAction(intent.getAction());

        if (intent.getAction().equals(context.getResources().getString(R.string.broadcast_startdiscovery))) {

            ConnectivityManager connManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            wifiBroadcastAddress = (mWifi.isConnected()) ? getWiFiBroadcastAddress(context) : null;
            startService = wifiBroadcastAddress != null;
            service.putExtra("wifiBroadcastAddress", wifiBroadcastAddress);
        }

        if (startService)
            startWakefulService(context, service);

        if (intent.getBooleanExtra("stopservice", false)) {
            context.stopService(service);
        }
    } else if (intent.getAction()
            .equals(context.getResources().getString(R.string.broadcast_startalarmrepeater))) {
        /**
         * start the alarm repeater only if WiFi is connected already
         * used by ServerListFragment.onServiceConnected method to start the discovery
         * if the application is launched being already connected to a WiFi network
         */
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        if (mWifi.isConnected()) {
            // if we're called from the activity, try to get a broadcast address
            if (intent.getBooleanExtra("forcegetbroadcast", false))
                wifiBroadcastAddress = getWiFiBroadcastAddress(context);
            startAlarmRepeater(context);
        } else {
            wifiBroadcastAddress = null;
        }
    } else if (intent.getAction()
            .equals(context.getResources().getString(R.string.broadcast_stopalarmrepeater))) {
        /**
         *  stop the alarm repeater. period.
         *  used by DrinViewerApplication.onTerminate method
         */
        wifiBroadcastAddress = null;
        stopAlarmRepeater(context);
    }
}

From source file:com.kii.sample.hellothingif.gcm.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    String error = null;//from www.j  a  v a  2s. c o  m
    try {
        synchronized (TAG) {
            InstanceID instanceID = InstanceID.getInstance(this);
            String senderId = getString(R.string.gcm_defaultSenderId);
            String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

            ThingIFAPI api = intent.getParcelableExtra(PARAM_THING_IF_API);
            api.installPush(token, PushBackend.GCM);
        }
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        error = e.getLocalizedMessage();
    }
    Intent registrationComplete = new Intent(INTENT_PUSH_REGISTRATION_COMPLETED);
    registrationComplete.putExtra(PARAM_ERROR_MESSAGE, error);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

From source file:org.ubicompforall.cityexplorer.gui.PoiDetailsActivity.java

/***
 * onCreate: StartUp Method//from w  w w. ja  v  a2  s.c  o  m
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.details_poi_layout);

    Intent myIntent = getIntent();
    if (myIntent.getParcelableExtra("poi") != null) {
        poi = (Poi) myIntent.getParcelableExtra("poi");
    } else {
        debug(0, "No poi supplied.. exit activity");
        this.finish();
    }

    if (myIntent.getParcelableExtra("trip") != null) {
        prevPoi = (ImageButton) findViewById(R.id.previousPoiButton); // TODO: POI MUST BE UPDATED WHEN THE ARROW ARE USED
        nextPoi = (ImageButton) findViewById(R.id.nextPoiButton);
        prevPoi.setVisibility(0);
        nextPoi.setVisibility(0);
        prevPoi.setOnClickListener(this);
        nextPoi.setOnClickListener(this);
        trip = myIntent.getParcelableExtra("trip");
        pois = new ArrayList<Poi>();
        for (Poi p : trip.getPois()) {
            pois.add(p);
        }
        poiNumber = myIntent.getIntExtra("poiNumber", 0);
        if (poiNumber == 0) {
            prevPoi.setEnabled(false);
            if (pois.size() == 1) {
                nextPoi.setEnabled(false);
            }
        } else if (poiNumber == pois.size() - 1) {
            nextPoi.setEnabled(false);
        }

    } else {
        debug(0, "No trip supplied..");
    }

    title = (TextView) findViewById(R.id.label);
    address = (TextView) findViewById(R.id.address);
    description = (TextView) findViewById(R.id.description);
    category = (TextView) findViewById(R.id.category);
    telephone = (TextView) findViewById(R.id.telephone);
    openingHours = (TextView) findViewById(R.id.openingHours);
    webPage = (TextView) findViewById(R.id.webPage);
    poiImage = (ImageView) findViewById(R.id.imageContainer);

    showPoiDetails(poi);
}

From source file:com.google.android.apps.iosched2.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.SCHED_SYNC, Context.MODE_PRIVATE);
    final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, VERSION_NONE);

    try {//  w  w  w  . j  a v  a2 s.  co 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) {
            // Load static local data
            mLocalExecutor.execute(Setup.BLOCKS_XML, new LocalBlocksHandler());
            mLocalExecutor.execute(Setup.ROOMS_XML, new LocalRoomsHandler());

            //                  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, Setup.EVENT_PREFIX + "cache-sessions.xml",
                    new RemoteSessionsHandler());
            mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "cache-speakers.xml",
                    new RemoteSpeakersHandler());

            if (Setup.FEATURE_VENDORS_ON) {
                mLocalExecutor.execute(context, Setup.EVENT_PREFIX + "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);
}