List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.wso2.mobile.mdm.api.PhoneState.java
/** *Returns the device battery information// www .jav a 2 s. com */ public float getBatteryLevel() { Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Error checking that probably isn't needed but I added just in case. if (level == -1 || scale == -1) { return 50.0f; } return ((float) level / (float) scale) * 100.0f; /*BroadcastReceiver batteryReceiver = new BroadcastReceiver() { int scale = -1; int level = -1; int voltage = -1; int temp = -1; @Override public void onReceive(Context context, Intent intent) { level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1); Log.v("Battery Level", "level is "+level+"/"+scale+", temp is "+temp+", voltage is "+voltage); Battery battery = Battery.getInstance(); battery.setLevel(level); battery.setScale(scale); battery.setTemp(temp); battery.setVoltage(voltage); } }; IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); context.registerReceiver(batteryReceiver, filter); return Battery.getInstance();*/ }
From source file:com.avalond.ad_blocak.vpn.AdVpnService.java
@Override public int onStartCommand(@Nullable Intent intent, int flags, int startId) { Log.i(TAG, "onStartCommand"); switch (intent == null ? Command.START : Command.values()[intent.getIntExtra("COMMAND", Command.START.ordinal())]) { case START:/*from w w w.j a v a 2s. com*/ startVpn(intent == null ? null : (PendingIntent) intent.getParcelableExtra("NOTIFICATION_INTENT")); break; case STOP: stopVpn(); break; } return Service.START_STICKY; }
From source file:com.cattle.PhotoSelectionActivity.java
/** * Called when the activity is first created. *//*from ww w . j a v a 2 s.c o m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choose_photos); mSinglePane = null == findViewById(R.id.frag_secondary); ActionBar ab = getSupportActionBar(); ab.setDisplayShowTitleEnabled(false); ab.addTab(ab.newTab().setText(R.string.tab_photos).setTag(TAB_PHOTOS).setTabListener(this)); if (mSinglePane) { ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ab.addTab(ab.newTab().setTag(TAB_SELECTED).setTabListener(this)); ab.addTab(ab.newTab().setText(R.string.tab_uploads).setTag(TAB_UPLOADS).setTabListener(this)); Intent intent = getIntent(); int defaultTab = intent.getIntExtra(EXTRA_DEFAULT_TAB, -1); if (defaultTab != -1) { ab.setSelectedNavigationItem(defaultTab); } } else { FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); replacePrimaryFragment(TAB_PHOTOS, ft); ft.commit(); } refreshSelectedPhotosTitle(); }
From source file:com.subzero.runners.android.AndroidLauncher.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1001) { int responseCode = data.getIntExtra("RESPONSE_CODE", 0); String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"); String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE"); if (resultCode == RESULT_OK) { try { JSONObject jo = new JSONObject(purchaseData); String sku = jo.getString("productId"); String name = null; if (sku.equals("ryan")) name = "Ryan"; else if (sku.equals("ash")) name = "Ash"; else if (sku.equals("rob")) name = "Rob"; else if (sku.equals("battle_cat")) name = "BattleCat"; else if (sku.equals("xorp")) name = "Xorp"; else if (sku.equals("rootsworth")) name = "Rootsworth"; else if (sku.equals("snap")) name = "Snap"; else if (sku.equals("metatron")) name = "Metatron"; else if (sku.equals("abaddon")) name = "Abaddon"; pref.putBoolean(name, true); pref.flush();/* w ww .j a va2 s .co m*/ } catch (JSONException e) { // alert("Failed to parse purchase data."); e.printStackTrace(); } } } super.onActivityResult(requestCode, resultCode, data); _gameHelper.onActivityResult(requestCode, resultCode, data); }
From source file:com.anenn.photopick.ImagePagerActivity.java
private void initValue() { Intent intent = getIntent(); mShowUris = intent.getStringArrayListExtra(SHOW_URIS); mPagerPosition = intent.getIntExtra(PAGER_POSITION, -1); mEditable = intent.getBooleanExtra(EDITABLE, false); String mSingleUri = intent.getStringExtra(SINGLE_URI); if (mSingleUri != null) { mShowUris = new ArrayList<>(); mShowUris.add(mSingleUri);//from w w w . ja v a 2s . c om mPagerPosition = 0; } View customActionBar = getLayoutInflater().inflate(R.layout.layout_image_pager_actionbar, null); tvImagePos = (TextView) customActionBar.findViewById(R.id.imagePos); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { if (mEditable) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setIcon(android.R.color.transparent); actionBar.setCustomView(customActionBar); actionBar.setDisplayShowCustomEnabled(true); viewPager.setBackgroundColor(getResources().getColor(R.color.bg_grep)); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { setPosDisplay(position); } @Override public void onPageScrollStateChanged(int state) { } }); setPosDisplay(0); } else { actionBar.hide(); viewPager.setBackgroundColor(getResources().getColor(android.R.color.black)); } } initPager(); }
From source file:com.cleanwiz.applock.files.activity.PhotoPreViewActivity.java
@Override protected void onStart() { super.onStart(); Intent intent = getIntent(); List<HideImageExt> hideImageExt = intent.getParcelableArrayListExtra("list"); int index = intent.getIntExtra("id", -1); mSamplePagerAdapter.setList(hideImageExt); if (index != -1) mViewPager.setCurrentItem(index); mViewpage_title.setVisibility(View.VISIBLE); }
From source file:com.doctoror.fuckoffmusicplayer.presentation.playback.PlaybackAndroidService.java
private void onActionPlay(@NonNull final Intent intent) { final List<Media> queue = intent.getParcelableArrayListExtra(EXTRA_QUEUE); final int position = intent.getIntExtra(EXTRA_POSITION, 0); service.play(queue, position);// w w w . j ava 2 s .c o m }
From source file:com.cyanogenmod.settings.otgtoggle.UsbDeviceMonitorService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent != null ? intent.getAction() : null; if (ACTION_SET_DETECTION_MODE.equals(action)) { int mode = intent.getIntExtra(EXTRA_MODE, -1); boolean permanent = intent.getBooleanExtra(EXTRA_PERMANENT, false); if (mode >= MODE_AUTO && mode <= MODE_OTG) { if (permanent) { mPrefs.edit().putInt(PREF_DETECTION_MODE, mode).apply(); }/*w w w. ja va2s . c om*/ mStateMachine.sendMessage(UsbPortStateMachine.DETECTION_MODE_CHANGED, mode); } } return START_STICKY; }
From source file:com.netpace.expressit.activity.UploadImageStoryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_upload_image_story); getSupportActionBar().setTitle("retake"); getSupportActionBar().setDisplayShowHomeEnabled(false); Intent intent = getIntent(); img_filePath = intent.getStringExtra(IMAGE_PATH); widthAfter = intent.getIntExtra(IMAGE_WIDTH, 0); heightAfter = intent.getIntExtra(IMAGE_HEIGHT, 0); isGalleryPhoto = intent.getBooleanExtra("isGalleryPhoto", false); imageViewThumbnail = (ImageView) findViewById(R.id.imageViewThumb); imageViewThumbnail.setImageURI(Uri.parse(img_filePath)); titleTextView = (TypefaceEditText) findViewById(R.id.story_title_txt_field); button_saveLater = (Button) findViewById(R.id.shareButton); button_saveLater.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (isValidate()) { // close the keyboard. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(titleTextView.getWindowToken(), 0); getMediaKeyFromRemoteServer(); }//w w w.j av a 2s.com } }); }
From source file:com.agenmate.lollipop.list.ListFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { int color = data.getIntExtra("color", 0); sheetLayout.setColor(ContextCompat.getColor(getActivity(), colorIds[color])); ((ListActivity) getActivity()).setStatusBarColor(color); }//from w ww. j ava 2 s . com presenter.result(requestCode, resultCode); }