Example usage for android.content Intent getBooleanExtra

List of usage examples for android.content Intent getBooleanExtra

Introduction

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

Prototype

public boolean getBooleanExtra(String name, boolean defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:io.indy.drone.service.ScheduledService.java

@Override
protected void onHandleIntent(Intent intent) {
    ifd("onHandleIntent");

    boolean isPullToRefresh = intent.getBooleanExtra(StrikeListActivity.ResponseReceiver.IS_PTR, false);
    if (isPullToRefresh) {
        ifd("invoked service via pull to refresh");
    }/*from   ww  w  .jav  a2s .c om*/

    mDatabase = new SQLDatabase(this);

    // called by a repeating alarm so update sharedpreferences with the current time
    updateAlarmTime();

    try {
        int serverCount = fetchStrikesCount();
        int localCount = mDatabase.getNumStrikes();

        if (localCount == 0) {
            ifd("localCount == 0");
            return;
        }

        if (localCount < serverCount) {
            // there's new strike data in the server
            ifd("new strike data found on server");
            JSONArray jsonStrikes = fetchNewStrikes(localCount);
            if (jsonStrikes == null) {
                ifd("fetching new strike data returned null");
                return;
            }

            ifd("adding strike data to local db");
            addStrikes(jsonStrikes);

            // event to inform list that new strike data is in the db
            EventBus.getDefault().post(new UpdatedDatabaseEvent());

            // create a notification
            if (!isPullToRefresh) {
                createNotification();
            }

        } else {
            ifd("serverCount (" + serverCount + ") not greater than localCount (" + localCount + ")");
        }

        if (isPullToRefresh) {
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction(StrikeListActivity.ResponseReceiver.ACTION_RESP);
            broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
            int diff = serverCount - localCount;
            broadcastIntent.putExtra(StrikeListActivity.ResponseReceiver.STRIKE_DIFF, diff);
            sendBroadcast(broadcastIntent);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.jvanhie.discogsscrobbler.util.NowPlayingService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getBooleanExtra(NEXT_TRACK_MODE, false)) {
        /*request to start scrobbling the next track, check if it is sound*/
        int pos = intent.getIntExtra(NEXT_TRACK_ID, 0);
        String title = intent.getStringExtra(NEXT_TRACK_TITLE);
        if (trackList != null && trackList.size() > 0) {
            //done listening to the previous track -> scrobble the previous track
            int now = (int) (System.currentTimeMillis() / 1000);
            mLastfm.scrobbleTrack(track, now, new Lastfm.LastfmWaiter() {
                @Override// ww  w .  j av  a  2s . co  m
                public void onResult(boolean success) {
                    //the user already sees the notification, no need for extras notifications atm.
                }
            });
            mTrackDone = 0;

            if (pos == -1 && trackList.get(0).title.equals(title)) {
                //stop requested
                stop();
            } else if (pos < trackList.size() && trackList.get(pos).title.equals(title)) {
                //ok, this is a valid request, make it happen
                play(pos);
            }
        }
        /*release the wakelock if it was called via the now playing alarm*/
        NowPlayingAlarm.completeWakefulIntent(intent);
    } else {
        /*we have received a playlist, start playing*/
        trackList = intent.getParcelableArrayListExtra(TRACK_LIST);
        thumb = intent.getStringExtra(THUMB_URL);
        albumArtURL = intent.getStringExtra(ALBUM_ART_URL);
        releaseId = intent.getLongExtra(RELEASE_ID, 0);
        currentTrack = 0;
        /*first try to load the album art, then start playing*/
        mImageLoader.loadImage(this, thumb, new ImageLoadingListener() {
            @Override
            public void onLoadingStarted() {
            }

            @Override
            public void onLoadingCancelled() {
            }

            @Override
            public void onLoadingFailed(FailReason failReason) {
                mNotificationBuilder.setLargeIcon(null);
                play(currentTrack);
            }

            @Override
            public void onLoadingComplete(Bitmap loadedImage) {
                mNotificationBuilder.setLargeIcon(loadedImage);
                play(currentTrack);
            }
        });
    }

    return (START_NOT_STICKY);
}

From source file:com.gh4a.activities.Github4AndroidActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_SETTINGS) {
        if (data.getBooleanExtra(SettingsActivity.RESULT_EXTRA_THEME_CHANGED, false)) {
            Intent intent = new Intent(getIntent());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);/*from w ww .jav a  2 s.com*/
            finish();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.ronnyml.sweetplayer.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mActivity = this;
    handleIntent(getIntent());/*from  ww  w .  ja v  a 2  s . c o  m*/

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerListView = (ListView) findViewById(R.id.navigation_drawer_listview);

    actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (!preferences.getBoolean(getString(R.string.is_first_time), false)) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(getString(R.string.is_first_time), true);
        editor.apply();
        showLegalMessage();
    }

    setupNavigationDrawer();
    if (savedInstanceState == null) {
        int fragment = 1;
        Intent intent = getIntent();
        if (intent != null) {
            if (intent.getBooleanExtra(Constants.IS_SEARCH, false)) {
                fragment = 0;
            } else if (intent.getBooleanExtra(Constants.IS_DOWNLOAD, false)) {
                fragment = 2;
            } else if (intent.getBooleanExtra(Constants.IS_PLAYLIST, false)
                    || intent.getBooleanExtra(Constants.IS_ARTIST, false)
                    || intent.getBooleanExtra(Constants.IS_GENRE, false)) {
                fragment = 5;
                mDetailTitle = intent.getStringExtra(Constants.NAME);
            }
        }

        selectItem(fragment);
    }
}

From source file:com.packpublishing.asynchronousandroid.chapter5.Sha1HashBroadCastUnhService.java

private void broadcastResult(final String text, final String digest) {

    Looper mainLooper = Looper.getMainLooper();
    Handler handler = new Handler(mainLooper);
    handler.post(new Runnable() {
        @Override/* w ww  .  j ava  2  s.  com*/
        public void run() {
            Intent intent = new Intent(DIGEST_BROADCAST);
            intent.putExtra(RESULT, digest);
            LocalBroadcastManager.getInstance(Sha1HashBroadCastUnhService.this).sendBroadcastSync(intent);
            boolean handled = intent.getBooleanExtra(HANDLED, false);
            if (!handled) {
                notifyUser(text, digest);
            }
        }
    });

}

From source file:com.android.systemui.ReminderReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    SharedPreferences shared = context.getSharedPreferences(KEY_REMINDER_ACTION, Context.MODE_PRIVATE);

    if (intent.getBooleanExtra("clear", false)) {
        manager.cancel(NOTI_ID);/*www . j av  a  2  s.c  o m*/
        // User has set a new reminder but didn't clear
        // This notification until now
        if (!shared.getBoolean("updated", false)) {
            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();
            shared.edit().putString("title", null).commit();
            shared.edit().putString("message", null).commit();
        }
    } else {
        String title = shared.getString("title", null);
        String message = shared.getString("message", null);
        if (title != null && message != null) {
            Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_qs_alarm_on);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setTicker(title)
                    .setContentTitle(title).setContentText(message).setAutoCancel(false).setOngoing(true)
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setSmallIcon(R.drawable.ic_qs_alarm_on)
                    .setLargeIcon(bm).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

            int alertMode = Settings.System.getIntForUser(context.getContentResolver(),
                    Settings.System.REMINDER_ALERT_NOTIFY, 0, UserHandle.USER_CURRENT);
            PendingIntent result = null;
            Intent serviceIntent = new Intent(context, ReminderService.class);
            if (alertMode != 0 && !QuietHoursHelper.inQuietHours(context, Settings.System.QUIET_HOURS_MUTE)) {
                context.startService(serviceIntent);
            }

            // Stop sound on click
            serviceIntent.putExtra("stopSelf", true);
            result = PendingIntent.getService(context, 1, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.setContentIntent(result);

            // Add button for dismissal
            serviceIntent.putExtra("dismissNoti", true);
            result = PendingIntent.getService(context, 0, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_sysbar_null,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_dismiss), result);

            // Add button for reminding later
            serviceIntent.putExtra("time", true);
            result = PendingIntent.getService(context, 2, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_qs_alarm_on,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_later), result);

            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();

            manager.notify(NOTI_ID, builder.build());
        }
    }
    shared.edit().putBoolean("updated", false).commit();
}

From source file:com.commonsware.android.service.ouroboros.AbstractSillyService.java

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
    Log.e(getClass().getSimpleName(), "onStartCommand() called");

    timer.schedule(new Runnable() {
        @Override//from ww  w. j av a  2s . c o  m
        public void run() {
            Intent next = new Intent(AbstractSillyService.this, getOtherClass());

            if (intent.getBooleanExtra(EXTRA_FOREGROUND, false)) {
                Log.e(getClass().getSimpleName(), "starting foreground");
                next.putExtra(EXTRA_FOREGROUND, true);
                getSystemService(NotificationManager.class).startServiceInForeground(next, 1337,
                        buildNotification(AbstractSillyService.this));
            } else if (intent.getBooleanExtra(EXTRA_BROADCAST_HACK, false)) {
                Log.e(getClass().getSimpleName(), "starting via broadcast hack");
                next.putExtra(EXTRA_BROADCAST_HACK, true);
                sendBroadcast(new Intent(AbstractSillyService.this, HackReceiver.class)
                        .putExtra(Intent.EXTRA_INTENT, next));
            } else {
                Log.e(getClass().getSimpleName(), "starting normal");
                startService(next);
            }
        }
    }, 1, TimeUnit.MINUTES);

    return (START_STICKY);
}

From source file:com.android.calendarDemo.alerts.DismissAlarmsService.java

@Override
public void onHandleIntent(Intent intent) {

    long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1);
    long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
    long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
    boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false);
    long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);

    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;/*  w ww .j  av  a2  s.c  o m*/

    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID
                + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0) {
        selection = buildMultipleEventsQuery(eventIds);
    } else {
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }

    ContentResolver resolver = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    resolver.update(uri, values, selection, null);

    // Remove from notification bar.
    if (notificationId != -1) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(notificationId);
    }

    if (showEvent) {
        // Show event on Calendar app by building an intent and task stack to start
        // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
        Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd);

        TaskStackBuilder.create(this).addParentStack(EventInfoActivity.class).addNextIntent(i)
                .startActivities();
    }

    // Stop this service
    stopSelf();
}

From source file:com.androidquery.simplefeed.activity.FriendsActivity.java

@Override
protected void init(Bundle savedInstanceState) {

    Intent intent = getIntent();
    if (intent != null) {
        selectable = intent.getBooleanExtra("selectable", false);
    }//from  w  w w.  j a  v a 2 s  .co  m

    initView();
}

From source file:ca.hoogit.garagepi.Controls.DoorManager.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getStringExtra(Consts.KEY_BROADCAST_ACTION);
    Log.d(TAG, "onReceive: Message received - Action: " + action);
    if (Consts.ACTION_DOORS_QUERY.equals(action)) {
        if (mQueryListener != null) {
            boolean wasSuccess = intent.getBooleanExtra(Consts.KEY_BROADCAST_SUCCESS, false);
            mQueryListener.onQuery(wasSuccess);
        }//from w  w  w.  j  ava  2  s.c  o  m
    } else if (Consts.ACTION_DOORS_TOGGLE.equals(action)) {
        if (mToggleListener != null) {
            String doorName = intent.getStringExtra(Consts.KEY_DOOR_ID);
            boolean wasSuccess = intent.getBooleanExtra(Consts.KEY_BROADCAST_SUCCESS, false);
            mToggleListener.onToggle(doorName, wasSuccess);
        }
    }
}