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.aashreys.walls.application.activities.StreamActivity.java

private void handleIntent(Intent intent) {
    int tabPosition = intent.getIntExtra(ARG_TAB_POSITION, 0);
    int totalTabs = viewPager != null ? viewPager.getAdapter().getCount() : 0;
    getViewModel().onReceiveTabPositionFromIntent(tabPosition, totalTabs);
}

From source file:com.contactlab.clabpush_android_sample.RegistrationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {

    int action = intent.getIntExtra(EXTRA_ACTION, ACTION_UNKNOWN);

    if (action == ACTION_REGISTER) {
        register();//www  .  j  a va 2s  .  c  om
    } else if (action == ACTION_UNREGISTER) {
        unregister();
    }
}

From source file:com.benlinskey.greekreference.syntax.SyntaxDetailActivity.java

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

    Intent intent = getIntent();
    mSyntaxId = intent.getIntExtra(ARG_SYNTAX_ID, -1);
    mSection = intent.getStringExtra(ARG_SECTION);

    mTitle = getString(R.string.title_syntax);

    // savedInstanceState is non-null when there is fragment state
    // saved from previous configurations of this activity
    // (e.g. when rotating the screen from portrait to landscape).
    // In this case, the fragment will automatically be re-added
    // to its container so we don't need to manually add it.
    // For more information, see the Fragments API guide at:
    ////from   w  ww.  ja v  a2 s  .c o m
    // http://developer.android.com/guide/components/fragments.html
    //
    if (savedInstanceState == null) {
        Bundle arguments = new Bundle();
        arguments.putString(SyntaxDetailFragment.ARG_XML,
                getIntent().getStringExtra(SyntaxDetailFragment.ARG_XML));
        SyntaxDetailFragment fragment = new SyntaxDetailFragment();
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().replace(R.id.item_detail_container, fragment)
                .commitAllowingStateLoss();
    }
}

From source file:com.benlinskey.greekreference.lexicon.LexiconDetailActivity.java

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

    Intent intent = getIntent();
    mLexiconId = intent.getIntExtra(ARG_LEXICON_ID, -1);
    mWord = intent.getStringExtra(ARG_WORD);

    mTitle = getString(R.string.title_lexicon);

    // savedInstanceState is non-null when there is fragment state
    // saved from previous configurations of this activity
    // (e.g. when rotating the screen from portrait to landscape).
    // In this case, the fragment will automatically be re-added
    // to its container so we don't need to manually add it.
    // For more information, see the Fragments API guide at:
    ////from   ww w.  ja  v  a 2  s .co  m
    // http://developer.android.com/guide/components/fragments.html
    if (savedInstanceState == null) {
        Bundle arguments = new Bundle();
        arguments.putString(LexiconDetailFragment.ARG_ENTRY,
                getIntent().getStringExtra(LexiconDetailFragment.ARG_ENTRY));
        LexiconDetailFragment fragment = new LexiconDetailFragment();
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().replace(R.id.item_detail_container, fragment)
                .commitAllowingStateLoss();
    }
}

From source file:com.dudka.rich.streamingmusicplayer.ServiceMusicPlayer.java

@Override
public int onStartCommand(Intent intent, int flags, int startID) {
    duration = intent.getIntExtra("duration", 0);
    String mediaFile = intent.getStringExtra("media_file");
    try {//  w ww . ja  v  a2  s  .  c  o m
        player = new MediaPlayer();
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.setDataSource(mediaFile);
        player.setOnPreparedListener(this);
        player.prepareAsync();
        player.setOnErrorListener(this);
    } catch (Exception e) {
        e.printStackTrace();
        sendLocalBroadcast(MainActivity.PLAYER_ERROR);
    }
    return START_STICKY;
}

From source file:com.commonsware.android.andcorder.RecorderService.java

@Override
public int onStartCommand(Intent i, int flags, int startId) {
    if (i.getAction() == null) {
        resultCode = i.getIntExtra(EXTRA_RESULT_CODE, 1337);
        resultData = i.getParcelableExtra(EXTRA_RESULT_INTENT);

        if (recordOnNextStart) {
            startRecorder();//  w  ww  .  j  ava  2 s. c om
        }

        foregroundify(!recordOnNextStart);
        recordOnNextStart = false;
    } else if (ACTION_RECORD.equals(i.getAction())) {
        if (resultData != null) {
            foregroundify(false);
            startRecorder();
        } else {
            Intent ui = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(ui);
            recordOnNextStart = true;
        }
    } else if (ACTION_STOP.equals(i.getAction())) {
        foregroundify(true);
        stopRecorder();
    } else if (ACTION_SHUTDOWN.equals(i.getAction())) {
        stopSelf();
    }

    return (START_NOT_STICKY);
}

From source file:com.android.bleserver.AdvertiserFragment.java

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

    advertisingFailureReceiver = new BroadcastReceiver() {

        /**//w  ww.j a  v  a2  s . co  m
         * Receives Advertising error codes from {@code AdvertiserService} and displays error messages
         * to the user. Sets the advertising toggle to 'false.'
         */
        @Override
        public void onReceive(Context context, Intent intent) {

            int errorCode = intent.getIntExtra(AdvertiserService.ADVERTISING_FAILED_EXTRA_CODE, -1);

            mSwitch.setChecked(false);

            String errorMessage = getString(R.string.start_error_prefix);
            switch (errorCode) {
            case AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED:
                errorMessage += " " + getString(R.string.start_error_already_started);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE:
                errorMessage += " " + getString(R.string.start_error_too_large);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED:
                errorMessage += " " + getString(R.string.start_error_unsupported);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR:
                errorMessage += " " + getString(R.string.start_error_internal);
                break;
            case AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS:
                errorMessage += " " + getString(R.string.start_error_too_many);
                break;
            case AdvertiserService.ADVERTISING_TIMED_OUT:
                errorMessage = " " + getString(R.string.advertising_timedout);
                break;
            default:
                errorMessage += " " + getString(R.string.start_error_unknown);
            }

            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_LONG).show();
        }
    };
}

From source file:com.avalond.ad_blocak.vpn.AdVpnService.java

private void connectivityChanged(Intent intent) {
    if (intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, 0) == ConnectivityManager.TYPE_VPN) {
        Log.i(TAG, "Ignoring connectivity changed for our own network");
        return;/*from   ww w . j  ava2 s  .c  o  m*/
    }

    if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        Log.e(TAG, "Got bad intent on connectivity changed " + intent.getAction());
    }
    if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
        Log.i(TAG, "Connectivity changed to no connectivity, wait for a network");
        waitForNetVpn();
    } else {
        Log.i(TAG, "Network changed, try to reconnect");
        reconnect();
    }
}

From source file:com.commonsware.andprojector.ProjectorService.java

@Override
public int onStartCommand(Intent i, int flags, int startId) {
    projection = mgr.getMediaProjection(i.getIntExtra(EXTRA_RESULT_CODE, -1),
            (Intent) i.getParcelableExtra(EXTRA_RESULT_INTENT));

    it = new ImageTransmogrifier(this);

    MediaProjection.Callback cb = new MediaProjection.Callback() {
        @Override/*from  w  ww .  j  a  va  2s .  co  m*/
        public void onStop() {
            vdisplay.release();
        }
    };

    vdisplay = projection.createVirtualDisplay("andprojector", it.getWidth(), it.getHeight(),
            getResources().getDisplayMetrics().densityDpi, VIRT_DISPLAY_FLAGS, it.getSurface(), null, handler);
    projection.registerCallback(cb, handler);

    return (START_NOT_STICKY);
}

From source file:com.polyvi.xface.extension.XBatteryExt.java

/**
 * ????json//from  w  w w  . j  a v a2s .  c o m
 *
 * @param batteryIntent ?????intent
 * @return ??json
 */
private JSONObject getBatteryInfo(Intent batteryIntent) {
    JSONObject obj = new JSONObject();
    try {
        obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0));
        obj.put("isPlugged",
                batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false);
    } catch (JSONException e) {
        XLog.e(CLASS_NAME, e.getMessage(), e);
    }
    return obj;
}