Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:by.zatta.pilight.connection.ConnectionService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    //??//from  w  w  w. j a  v  a 2 s  .co m

    sendMessageToUI(MSG_SET_STATUS, mCurrentNotif.name());
    if (intent.hasExtra("command") && isConnectionUp) {
        Server.CONNECTION
                .sentCommand("{\"message\":\"send\",\"code\":{" + intent.getStringExtra("command") + "}}");
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(aCtx);
        boolean useService = prefs.getBoolean("useService", true);
        if (!useService) {
            if (mWM == null || !mWM.isAlive()) {
                mWM = new WriteMonitor();
                mWM.setName("WriteMonitor");
                mWM.start();
            }
        }
    }
    return START_STICKY;
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_OK && requestCode == DETAILS_REQUEST_CODE) {

        if (intent.hasExtra(Intents.History.ITEM_NUMBER)) {
            int position = intent.getIntExtra(Intents.History.ITEM_NUMBER, -1);

            HistoryItem item = mHistoryManager.buildHistoryItem(position);

            this.historyFragment.updatePosition(position, item);
        }//from  w ww  .  j a  v  a2s.co m
    }
}

From source file:com.google.android.apps.iosched.ui.tablet.SessionsVendorsMultiPaneActivity.java

private void routeIntent(Intent intent, boolean updateSurfaceOnly) {
    Uri uri = intent.getData();/*from ww w  .  ja v a2s. c  om*/
    if (uri == null) {
        return;
    }

    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
        setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    String mimeType = getContentResolver().getType(uri);

    if (ScheduleContract.Tracks.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load track details
        showFullUI(true);
        if (!updateSurfaceOnly) {
            // TODO: don't assume the URI will contain the track ID
            String selectedTrackId = ScheduleContract.Tracks.getTrackId(uri);
            loadTrackList(TracksDropdownFragment.VIEW_TYPE_SESSIONS, selectedTrackId);
            onTrackSelected(selectedTrackId);
            if (mShowHideMasterLayout != null) {
                mShowHideMasterLayout.showMaster(true, ShowHideMasterLayout.FLAG_IMMEDIATE);
            }
        }

    } else if (ScheduleContract.Sessions.CONTENT_TYPE.equals(mimeType)) {
        // Load a session list, hiding the tracks dropdown and the tabs
        mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            loadSessionList(uri, null);
            if (mShowHideMasterLayout != null) {
                mShowHideMasterLayout.showMaster(true, ShowHideMasterLayout.FLAG_IMMEDIATE);
            }
        }

    } else if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load session details
        if (intent.hasExtra(EXTRA_MASTER_URI)) {
            mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
            showFullUI(false);
            if (!updateSurfaceOnly) {
                loadSessionList((Uri) intent.getParcelableExtra(EXTRA_MASTER_URI),
                        ScheduleContract.Sessions.getSessionId(uri));
                loadSessionDetail(uri);
            }
        } else {
            mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; // prepare for onTrackInfo...
            showFullUI(true);
            if (!updateSurfaceOnly) {
                loadSessionDetail(uri);
                loadTrackInfoFromSessionUri(uri);
            }
        }

    } else if (ScheduleContract.Vendors.CONTENT_TYPE.equals(mimeType)) {
        // Load a vendor list
        mViewType = TracksDropdownFragment.VIEW_TYPE_VENDORS;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            loadVendorList(uri, null);
            if (mShowHideMasterLayout != null) {
                mShowHideMasterLayout.showMaster(true, ShowHideMasterLayout.FLAG_IMMEDIATE);
            }
        }

    } else if (ScheduleContract.Vendors.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load vendor details
        mViewType = TracksDropdownFragment.VIEW_TYPE_VENDORS;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            Uri masterUri = (Uri) intent.getParcelableExtra(EXTRA_MASTER_URI);
            if (masterUri == null) {
                masterUri = ScheduleContract.Vendors.CONTENT_URI;
            }
            loadVendorList(masterUri, ScheduleContract.Vendors.getVendorId(uri));
            loadVendorDetail(uri);
        }
    }

    updateDetailBackground();
}

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public void fireAlarm(Intent intent) throws InterruptedException {

    Context c = App.getContext();

    if ((intent == null) || !intent.hasExtra("json")) {

        return;/*from ww  w .  j ava2s  . c o m*/
    }
    Alarm next = Alarm.fromString(intent.getStringExtra("json"));
    intent.removeExtra("json");

    if (next.city == 0) {
        return;
    }

    Times t = Times.getTimes(next.city);
    if (t == null)
        return;
    boolean active;
    if (next.cuma) {
        active = t.isCumaActive();
    } else if (next.early) {
        active = t.isEarlyNotificationActive(next.vakit);
    } else {
        active = t.isNotificationActive(next.vakit);
    }
    if (!active) {
        return;
    }

    boolean vibrate;
    String sound;
    String dua;
    long silenter;
    if (next.cuma) {
        vibrate = t.hasCumaVibration();
        sound = t.getCumaSound();
        dua = "silent";
        silenter = t.getCumaSilenterDuration();
    } else if (next.early) {
        vibrate = t.hasEarlyVibration(next.vakit);
        sound = t.getEarlySound(next.vakit);
        dua = "silent";
        silenter = t.getEarlySilenterDuration(next.vakit);
    } else {
        vibrate = t.hasVibration(next.vakit);
        sound = t.getSound(next.vakit);
        dua = t.getDua(next.vakit);
        silenter = t.getSilenterDuration(next.vakit);
    }

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

    nm.cancel(next.city + "", NotIds.ALARM);
    String text;

    text = t.getName() + " (" + t.getSource() + ")";

    String txt = "";
    if (next.early) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index],
                "" + t.getEarlyTime(next.vakit));
    } else if (next.cuma) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index], "" + t.getCumaTime());
    } else if (next.vakit != null) {
        txt = next.vakit.getString();
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(text)
            .setContentText(txt).setContentIntent(Main.getPendingIntent(t)).setSmallIcon(R.drawable.ic_abicon);
    Notification not = builder.build();

    if (vibrate) {
        not.vibrate = VibrationPreference.getPattern(c, "vibration");
    }

    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    class MPHolder {
        MediaPlayer mp;
    }
    not.deleteIntent = PendingIntent.getBroadcast(c, 0, new Intent(c, Audio.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    nm.notify(next.city + "", NotIds.ALARM, not);

    final MPHolder mp = new MPHolder();

    if (Prefs.showNotificationScreen() && (sound != null) && !sound.startsWith("silent")) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isScreenOn()) {
            Intent i = new Intent(c, NotificationPopup.class);
            i.putExtra("city", next.city);
            i.putExtra("name", text);
            i.putExtra("vakit", txt);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            c.startActivity(i);

            Thread.sleep(1000);
        }
    }

    sInterrupt = false;
    boolean hasSound = false;
    while ((sound != null) && !sound.startsWith("silent") && !sInterrupt) {
        int volume = -2;
        hasSound = true;

        if (!sound.startsWith("silent") && !sound.startsWith("picker")) {

            if (sound.contains("$volume")) {
                volume = Integer.parseInt(sound.substring(sound.indexOf("$volume") + 7));
                sound = sound.substring(0, sound.indexOf("$volume"));
            }
            if (volume != -2) {
                int oldvalue = am.getStreamVolume(getStreamType(c));
                am.setStreamVolume(getStreamType(c), volume, 0);
                volume = oldvalue;
            }

            try {
                mp.mp = play(c, sound);
            } catch (IOException e) {
                e.printStackTrace();
                if (next.cuma) {
                    t.setCumaSound("silent");
                } else if (next.early) {
                    t.setEarlySound(next.vakit, "silent");
                } else {
                    if ("sound".equals(t.getSound(next.vakit))) {
                        t.setSound(next.vakit, "silent");
                    } else {
                        t.setDua(next.vakit, "silent");
                    }
                }
                mp.mp = null;
            }

            if (mp.mp != null) {

                mp.mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

                mp.mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                    @Override
                    public void onSeekComplete(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

            }

            sInterrupt = false;

            while ((mp.mp != null) && mp.mp.isPlaying()) {
                if (sInterrupt) {
                    mp.mp.stop();
                    mp.mp.release();
                    mp.mp = null;

                    dua = null;
                } else {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ignore) {
                    }
                }
            }
            sInterrupt = false;

        }

        if (volume != -2) {
            am.setStreamVolume(getStreamType(c), volume, 0);
        }
        sound = dua;
        dua = null;
    }

    if (hasSound && Prefs.autoRemoveNotification()) {
        nm.cancel(next.city + "", NotIds.ALARM);
    }
    if (silenter != 0) {
        silenter(c, silenter);
    }

}

From source file:com.github.play.app.StatusService.java

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        String intentKey = intent.getStringExtra(EXTRA_KEY);
        if (!TextUtils.isEmpty(intentKey) && !intentKey.equals(applicationKey)) {
            destroyPusher(pusher);//from w ww  . ja  va2s. c o  m
            createPusher(intentKey);
        }

        boolean updateNotification = intent.hasExtra(EXTRA_NOTIFY);
        if (updateNotification)
            sendNotification = intent.getBooleanExtra(EXTRA_NOTIFY, false);
        Song song = (Song) intent.getSerializableExtra(EXTRA_SONG);
        if (updateNotification && !sendNotification) {
            clearNotification();
        } else if (song != null)
            updateNotification(song);
    }

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

From source file:cd.education.data.collector.android.activities.GeoPointMapActivity.java

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

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }/*from www . java 2  s  . c  o  m*/

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.geopoint_layout);

    Intent intent = getIntent();

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mLatLng = new LatLng(location[0], location[1]);
        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }
        mCaptureLocation = !intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
        mRefreshLocation = mCaptureLocation;
    }

    /* Set up the map and the marker */
    mMarkerOption = new MarkerOptions();
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    mMap.setOnMarkerDragListener(this);

    mLocationStatus = (TextView) findViewById(R.id.location_status);

    /*Zoom only if there's a previous location*/
    if (mLatLng != null) {
        mLocationStatus.setVisibility(View.GONE);
        mMarkerOption.position(mLatLng);
        mMarker = mMap.addMarker(mMarkerOption);
        mRefreshLocation = false; // just show this position; don't change it...
        mMarker.setDraggable(mCaptureLocation);
        mZoomed = true;
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
    }

    mCancelLocation = (Button) findViewById(R.id.cancel_location);
    mCancelLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "cancelLocation", "cancel");
            finish();
        }
    });

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // make sure we have a good location provider before continuing
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;
        }
        if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
        }
    }
    if (!mGPSOn && !mNetworkOn) {
        Toast.makeText(getBaseContext(), getString(R.string.provider_disabled_error), Toast.LENGTH_SHORT)
                .show();
        finish();
    }

    if (mGPSOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) null location");
        }
    }

    if (mNetworkOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) null location");
        }
    }

    mAcceptLocation = (Button) findViewById(R.id.accept_location);
    if (mCaptureLocation) {
        mAcceptLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation", "OK");
                returnLocation();
            }
        });
        mMap.setOnMapLongClickListener(this);
    } else {
        mAcceptLocation.setVisibility(View.GONE);
    }

    mReloadLocation = (Button) findViewById(R.id.reload_location);
    if (mCaptureLocation) {
        mReloadLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mRefreshLocation = true;
                mReloadLocation.setVisibility(View.GONE);
                mLocationStatus.setVisibility(View.VISIBLE);
                if (mGPSOn) {
                    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            GeoPointMapActivity.this);
                }
                if (mNetworkOn) {
                    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            GeoPointMapActivity.this);
                }
            }

        });
        mReloadLocation.setVisibility(!mRefreshLocation ? View.VISIBLE : View.GONE);
    } else {
        mReloadLocation.setVisibility(View.GONE);
    }

    // Focuses on marked location
    mShowLocation = ((Button) findViewById(R.id.show_location));
    mShowLocation.setVisibility(View.VISIBLE);
    mShowLocation.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "showLocation", "onClick");
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
        }
    });
    mShowLocation.setClickable(mMarker != null);

}

From source file:com.company.millenium.iwannask.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    if (intent.hasExtra("url")) {
        String url = intent.getStringExtra("url");
        //            myWebView.loadUrl(Constants.SERVER_URL + url);
    }/*from w ww  . j a  v a  2 s  . c o  m*/
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.SessionsSandboxMultiPaneActivity.java

private void routeIntent(Intent intent, boolean updateSurfaceOnly) {
    Uri uri = intent.getData();/*from w ww .java  2 s.c  o  m*/
    if (uri == null) {
        return;
    }

    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
        setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    String mimeType = getContentResolver().getType(uri);

    if (ScheduleContract.Tracks.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load track details
        showFullUI(true);
        if (!updateSurfaceOnly) {
            // TODO: don't assume the URI will contain the track ID
            int defaultViewType = intent.getIntExtra(EXTRA_DEFAULT_VIEW_TYPE,
                    TracksDropdownFragment.VIEW_TYPE_SESSIONS);
            String selectedTrackId = ScheduleContract.Tracks.getTrackId(uri);
            loadTrackList(defaultViewType, selectedTrackId);
            getSupportActionBar().setSelectedNavigationItem(defaultViewType);
            onTrackSelected(selectedTrackId);
            mSlidingPaneLayout.openPane();
        }

    } else if (ScheduleContract.Sessions.CONTENT_TYPE.equals(mimeType)) {
        // Load a session list, hiding the tracks dropdown and the tabs
        mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            loadSessionList(uri, null);
            mSlidingPaneLayout.openPane();
        }

    } else if (ScheduleContract.Sessions.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load session details
        if (intent.hasExtra(EXTRA_MASTER_URI)) {
            mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS;
            showFullUI(false);
            if (!updateSurfaceOnly) {
                loadSessionList((Uri) intent.getParcelableExtra(EXTRA_MASTER_URI),
                        ScheduleContract.Sessions.getSessionId(uri));
                loadSessionDetail(uri);
            }
        } else {
            mViewType = TracksDropdownFragment.VIEW_TYPE_SESSIONS; // prepare for onTrackInfo...
            showFullUI(true);
            if (!updateSurfaceOnly) {
                loadSessionDetail(uri);
                loadTrackInfoFromSessionUri(uri);
            }
        }

    } else if (ScheduleContract.Sandbox.CONTENT_TYPE.equals(mimeType)) {
        // Load a sandbox company list
        mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            loadSandboxList(uri, null);
            mSlidingPaneLayout.openPane();
        }

    } else if (ScheduleContract.Sandbox.CONTENT_ITEM_TYPE.equals(mimeType)) {
        // Load company details
        mViewType = TracksDropdownFragment.VIEW_TYPE_SANDBOX;
        showFullUI(false);
        if (!updateSurfaceOnly) {
            Uri masterUri = intent.getParcelableExtra(EXTRA_MASTER_URI);
            if (masterUri == null) {
                masterUri = ScheduleContract.Sandbox.CONTENT_URI;
            }
            loadSandboxList(masterUri, ScheduleContract.Sandbox.getCompanyId(uri));
            loadSandboxDetail(uri);
        }
    }

    updateDetailBackground();
}

From source file:com.mpower.clientcollection.activities.GeoPointMapActivity.java

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

    if (savedInstanceState != null) {
        mLocationCount = savedInstanceState.getInt(LOCATION_COUNT);
    }/*w  ww.  ja  v  a 2s  . c o m*/

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.geopoint_layout);

    Intent intent = getIntent();

    mLocationAccuracy = GeoPointWidget.DEFAULT_LOCATION_ACCURACY;
    if (intent != null && intent.getExtras() != null) {
        if (intent.hasExtra(GeoPointWidget.LOCATION)) {
            double[] location = intent.getDoubleArrayExtra(GeoPointWidget.LOCATION);
            mLatLng = new LatLng(location[0], location[1]);
        }
        if (intent.hasExtra(GeoPointWidget.ACCURACY_THRESHOLD)) {
            mLocationAccuracy = intent.getDoubleExtra(GeoPointWidget.ACCURACY_THRESHOLD,
                    GeoPointWidget.DEFAULT_LOCATION_ACCURACY);
        }
        mCaptureLocation = !intent.getBooleanExtra(GeoPointWidget.READ_ONLY, false);
        mRefreshLocation = mCaptureLocation;
    }

    /* Set up the map and the marker */
    mMarkerOption = new MarkerOptions();
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    mMap.setOnMarkerDragListener(this);

    mLocationStatus = (TextView) findViewById(R.id.location_status);

    /*Zoom only if there's a previous location*/
    if (mLatLng != null) {
        mLocationStatus.setVisibility(View.GONE);
        mMarkerOption.position(mLatLng);
        mMarker = mMap.addMarker(mMarkerOption);
        mRefreshLocation = false; // just show this position; don't change it...
        mMarker.setDraggable(mCaptureLocation);
        mZoomed = true;
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
    }

    mCancelLocation = (Button) findViewById(R.id.cancel_location);
    mCancelLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ClientCollection.getInstance().getActivityLogger().logInstanceAction(this, "cancelLocation",
                    "cancel");
            finish();
        }
    });

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // make sure we have a good location provider before continuing
    List<String> providers = mLocationManager.getProviders(true);
    for (String provider : providers) {
        if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) {
            mGPSOn = true;
        }
        if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) {
            mNetworkOn = true;
        }
    }
    if (!mGPSOn && !mNetworkOn) {
        Toast.makeText(getBaseContext(), getString(R.string.provider_disabled_error), Toast.LENGTH_SHORT)
                .show();
        finish();
    }

    if (mGPSOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(GPS) null location");
        }
    }

    if (mNetworkOn) {
        Location loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (loc != null) {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) lat: " + loc.getLatitude() + " long: " + loc.getLongitude()
                    + " acc: " + loc.getAccuracy());
        } else {
            InfoLogger.geolog("GeoPointMapActivity: " + System.currentTimeMillis()
                    + " lastKnownLocation(Network) null location");
        }
    }

    mAcceptLocation = (Button) findViewById(R.id.accept_location);
    if (mCaptureLocation) {
        mAcceptLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                ClientCollection.getInstance().getActivityLogger().logInstanceAction(this, "acceptLocation",
                        "OK");
                returnLocation();
            }
        });
        mMap.setOnMapLongClickListener(this);
    } else {
        mAcceptLocation.setVisibility(View.GONE);
    }

    mReloadLocation = (Button) findViewById(R.id.reload_location);
    if (mCaptureLocation) {
        mReloadLocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mRefreshLocation = true;
                mReloadLocation.setVisibility(View.GONE);
                mLocationStatus.setVisibility(View.VISIBLE);
                if (mGPSOn) {
                    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            GeoPointMapActivity.this);
                }
                if (mNetworkOn) {
                    mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            GeoPointMapActivity.this);
                }
            }

        });
        mReloadLocation.setVisibility(!mRefreshLocation ? View.VISIBLE : View.GONE);
    } else {
        mReloadLocation.setVisibility(View.GONE);
    }

    // Focuses on marked location
    mShowLocation = ((Button) findViewById(R.id.show_location));
    mShowLocation.setVisibility(View.VISIBLE);
    mShowLocation.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ClientCollection.getInstance().getActivityLogger().logInstanceAction(this, "showLocation",
                    "onClick");
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16));
        }
    });
    mShowLocation.setClickable(mMarker != null);

}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    LOGD(TAG, "onNewIntent, extras " + intent.getExtras());
    if (intent.hasExtra(EXTRA_DIALOG_MESSAGE)) {
        mShowedAnnouncementDialog = false;
        showAnnouncementDialogIfNeeded(intent);
    }/*from w w w. ja v  a 2s.  co  m*/
}