Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

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

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.alainesp.fan.sanderson.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    staticRef = this;

    super.onCreate(savedInstanceState);
    DB.currentContext = this;
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  ww w . j  av  a2s  .co m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu drawerMenu = navigationView.getMenu();
    // Create the hashtable
    reverseMenuText.clear();
    for (int i = 0; i < drawerMenu.size(); i++)
        reverseMenuText.put(drawerMenu.getItem(i).getTitle().toString(), i);
    navigationView.setNavigationItemSelectedListener(this);
    // 2 listeners to show the badges
    navigationView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View vv, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            setBadgesNumberUI();
        }
    });
    ((NavigationMenuView) navigationView.getChildAt(0))
            .addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    setBadgesNumberUI();
                }
            });

    // Select Summary at the beginning
    loadBadgeNumbers();
    // Try to load the state in which the app was
    if (savedInstanceState != null)
        app_state = savedInstanceState.getInt(APP_FRAGMENT_INDEX);
    else {
        Intent intent = getIntent();
        if (intent != null)
            app_state = intent.getIntExtra(APP_FRAGMENT_INDEX, -2);

        if (app_state == -2)
            app_state = APP_STATE_SUMMARY;
    }

    if (app_state == APP_STATE_ABOUT)
        onAboutClick(null);
    else
        navigateTo((app_state));
}

From source file:com.dattasmoon.pebble.plugin.FireReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
        // fetch this for later, we may need it in case we change things
        // around and we need to know what version of the code they were
        // running when they saved the action
        int bundleVersionCode = intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_VERSION_CODE, 1);

        Type type = Type.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_TYPE,
                Type.NOTIFICATION.ordinal())];
        PowerManager pm;/*from  w ww  .ja  v a2  s  .c  o  m*/
        switch (type) {
        case NOTIFICATION:
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);

            // handle screen DND
            boolean notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true);
            pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (Constants.IS_LOGGABLE) {
                Log.d(Constants.LOG_TAG, "FireReceiver.onReceive: notifScreenOn=" + notifScreenOn + "  screen="
                        + pm.isScreenOn());
            }
            if (!notifScreenOn && pm.isScreenOn()) {
                break;
            }

            //handle quiet hours DND
            boolean quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false);
            //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha)
            if (quiet_hours) {
                String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00")
                        .split(":");
                Date quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":");
                Date quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                Calendar c = Calendar.getInstance();
                Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs "
                            + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
                }
                if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning.");
                    }
                    break;
                }
            }

            String title = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_TITLE);
            String body = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_BODY);

            sendAlertToPebble(context, bundleVersionCode, title, body);
            break;
        case SETTINGS:
            Mode mode = Mode.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_MODE, Mode.OFF.ordinal())];
            String packageList = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_PACKAGE_LIST);

            setNotificationSettings(context, bundleVersionCode, mode, packageList);
            break;
        }
    }
}

From source file:org.dvbviewer.controller.service.SyncService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        int intentFlags = intent.getIntExtra(ACTION_EXTRA, 0);
        Message msg;/*  w  w w. ja v a2s .c  o  m*/
        switch (intentFlags) {
        case SYNC_CHANNELS:
            msg = mServiceHandler.obtainMessage();
            msg.what = SYNC_CHANNELS;
            msg.arg1 = startId;
            msg.arg2 = flags;
            msg.setData(intent.getExtras());
            mServiceHandler.sendMessage(msg);
            Log.i("ServiceStartArguments", "Sending: " + msg);
            break;
        case SYNC_EPG:
            msg = mServiceHandler.obtainMessage();
            msg.what = SYNC_EPG;
            msg.arg1 = startId;
            msg.arg2 = flags;
            msg.setData(intent.getExtras());
            mServiceHandler.sendMessage(msg);
            Log.i("ServiceStartArguments", "Sending: " + msg);

            // EpgSyncronizer epgSyncer = new EpgSyncronizer();
            // epgSyncer.execute(intent);
            break;
        default:
            stopSelf();
            break;
        }
    } else {
        // switch (startId) {
        // case mChannelSyncId:
        //
        // break;
        //
        // default:
        // break;
        // }
    }
    return START_REDELIVER_INTENT;
}

From source file:com.iss.android.wearable.datalayer.MainActivity.java

private void initializeSWBatteryChecker() {
    final TextView SWBatteryStatus = (TextView) findViewById(R.id.SWbatteryLabel);
    final Handler h = new Handler();
    final int delay = 20000; //milliseconds
    final boolean[] warned_evening = { false };

    // Timer's fine for Java, but kills android apps.

    h.postDelayed(new Runnable() {
        public void run() {
            IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
            Intent batteryStatus = registerReceiver(null, ifilter);

            int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

            int batteryPct = (int) (level / (float) scale * 100);
            SWBatteryStatus.setText("SW: " + batteryPct + "%");
            Calendar clnd = Calendar.getInstance();
            if (clnd.get(Calendar.HOUR_OF_DAY) >= 20) {
                if (batteryPct < 75 && !warned_evening[0]) {
                    warned_evening[0] = true;
                    displaySWBatteryWarning();
                } else if (batteryPct >= 75 && warned_evening[0]) {
                    warned_evening[0] = false;
                }//from w  w w  .j a  v  a 2  s  .com
            }
            h.postDelayed(this, delay);
        }
    }, 0);
}

From source file:anakiou.com.picontrol.service.OutputIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    receiver = intent.getParcelableExtra(Constants.RECEIVER);

    if (!networkService.isNetworkAvailableAndConnected()) {

        deliverResultToReceiver(Constants.FAILURE_RESULT, getString(R.string.network_required_msg));

        return;/*www. ja v  a 2 s  .  c  o  m*/
    }

    int operationType = intent.getIntExtra(Constants.EXTRA_OPERATION_TYPE, 0);

    switch (operationType) {
    case Constants.OP_OUTPUT_GET:
        handleGet();
        break;
    case Constants.OP_OUTPUT_STATUS_ALL_GET:
        handleStatusAllGet();
        break;
    case Constants.OP_OUTPUT_NAME_SET:
        handleNameSet(intent);
        break;
    case Constants.OP_OUTPUT_SINGLE_CONTROL:
        handleSingleControl(intent);
        break;
    case Constants.OP_OUTPUT_CONTROL_ALL:
        handleControlAll(intent);
        break;
    }
}

From source file:org.mythdroid.util.UpdateService.java

private void handleCommand(final Intent intent) {

    switch (intent.getIntExtra(ACTION, CHECKMD)) {

    case CHECKMD:
        Globals.runOnWorker(new Runnable() {
            @Override//from w  ww .  j a v a  2 s  .c o  m
            public void run() {
                checkMythDroid();
            }
        });
        break;

    case CHECKMDD:
        Globals.runOnWorker(new Runnable() {
            @Override
            public void run() {
                checkMDD(intent.getStringExtra(ADDR));
            }
        });
        break;

    case UPDATEMD:
        Globals.runOnWorker(new Runnable() {
            @Override
            public void run() {
                updateMythDroid(intent.getStringExtra(VER), intent.getStringExtra(URL));
            }
        });
        break;

    case UPDATEMDD:
        Globals.runOnWorker(new Runnable() {
            @Override
            public void run() {
                updateMDD(intent.getStringExtra(ADDR), intent.getStringExtra(VER), intent.getStringExtra(URL));
            }
        });
        break;
    }

}

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;//from ww w  .j  a va 2s  .com

    // 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.android.nsboc.ComposeFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == ComposeActivity.RESULT_OK) {
        if (requestCode == ComposeActivity.REQUEST_IMAGE_CAPTURE) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");

            int selectorId = data.getIntExtra("image_selector_id", -1);
            if (selectorId != -1) {
                TextView selectorLabel = (TextView) mRootView.findViewById(selectorId);
                if (selectorLabel != null) {
                    Drawable imagePreview = new BitmapDrawable(getResources(), imageBitmap);
                    selectorLabel.setCompoundDrawablesWithIntrinsicBounds(imagePreview, null, null, null);
                }/*from   w  w  w .ja  v  a  2  s  .c  o m*/
            }

        } else if (requestCode == ComposeActivity.REQUEST_FROM_GALLERY
                || requestCode == ComposeActivity.REQUEST_SIGNATURE) {
            Uri imageUri = data.getData();
            String imagePath = getPath(imageUri);
            Drawable imagePreview = Drawable.createFromPath(imagePath);

            int selectorId = data.getIntExtra("image_selector_id", -1);
            if (selectorId != -1) {
                TextView selectorLabel = (TextView) mRootView.findViewById(selectorId);
                if (selectorLabel != null) {
                    selectorLabel.setCompoundDrawablesWithIntrinsicBounds(imagePreview, null, null, null);
                }
            }
        }
    }
}

From source file:cc.arduino.mvd.services.ElisService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (!started) {

        url = intent.getStringExtra(MvdServiceReceiver.EXTRA_SERVICE_URL);

        port = intent.getIntExtra(MvdServiceReceiver.EXTRA_SERVICE_PORT, 11414);

        List<BasicNameValuePair> extraHeaders = new ArrayList<>();

        URI uri = URI.create(url + ":" + port);

        webSocketClient = new WebSocketClient(uri, webSocketListener, extraHeaders);

        webSocketClient.connect();/*from  www.  j ava2 s  .co m*/

        started = true;

        if (DEBUG) {
            Log.d(TAG, TAG + " started.");
        }
    }

    return START_STICKY;
}

From source file:cn.com.incito.driver.UI.detailDialog.PCCFragmentActivity.java

@SuppressWarnings("unchecked")
@Override//  w w w.  j  a  va2 s .  c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("test1", "onCreate");
    setContentView(R.layout.activity_pcc_main);

    mContext = this;
    Intent i = getIntent();
    mFlag = i.getIntExtra("selectmodel", FLAG_SINGELSELECTION);
    totals = i.getIntExtra("totals", -1);
    totals_error = i.getStringExtra("totals_error");
    number = (TextView) findViewById(R.id.number);
    if (mFlag == FLAG_SINGELSELECTION) {
        number.setText(String.valueOf(1));
    } else {
        totals = totals != -1 ? totals : 5;
        number.setText(String.valueOf(totals));
    }

    if (mFlag == FLAG_MULTIPLESELECTION) {
        selectedCities = (ArrayList<ModelSelectedCity>) i.getSerializableExtra("selectedCities");
    }
    if (selectedCities == null) {
        selectedCities = new ArrayList<ModelSelectedCity>();
    }
    if (selectedCities.size() > 0) {
        mCurrentSelected = selectedCities.size() - 1;
    }

    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    pager = (ViewPager) findViewById(R.id.pager);
    adapter = new MyPagerAdapter(getSupportFragmentManager());
    textProvince = (TextView) findViewById(R.id.textProvince);
    textCity = (TextView) findViewById(R.id.textCity);
    textCountry = (TextView) findViewById(R.id.textCountry);

    btn_confirm = (Button) findViewById(R.id.btn_confirm);
    btn_cancle = (Button) findViewById(R.id.btn_cancle);
    btn_confirm.setOnClickListener(this);
    btn_cancle.setOnClickListener(this);
    setSelectedBtnsListener();
    pager.setAdapter(adapter);

    final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
            getResources().getDisplayMetrics());
    pager.setPageMargin(pageMargin);

    tabs.setViewPager(pager);

    provinceFragment = new ProvinceFragment(mContext, handler);
    cityFragment = new CityFragment(mContext, handler);
    countryFragment = new CountryFragment(mContext, handler);
    listFragments.add(provinceFragment);
    listFragments.add(cityFragment);
    listFragments.add(countryFragment);
    notifySelectedCities();
}