List of usage examples for android.content Intent getIntExtra
public int getIntExtra(String name, int defaultValue)
From source file:com.remobile.batteryStatus.BatteryListener.java
/** * Creates a JSONObject with the current battery information * * @param batteryIntent the current battery information * @return a JSONObject containing the battery status information *//*from w ww . j a v a 2 s . com*/ 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) { LOG.e(LOG_TAG, e.getMessage(), e); } return obj; }
From source file:de.damdi.fitness.activity.settings.sync.OpenTrainingSyncService.java
protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent()"); version = intent.getIntExtra(EXTRA_VERSION_CODE, -1); host = intent.getStringExtra(EXTRA_HOST); mReceiver = intent.getParcelableExtra("receiver"); String command = intent.getStringExtra("command"); Bundle b = new Bundle(); if (command.equals("query")) { try {/*from w w w . ja v a 2s . co m*/ // set up REST-Client mClient = new RestClient(host, port, "https", version); // download and parse the exercises ArrayList<ExerciseType> allExercises = downloadAndParseExercises(); // add data to bundle b.putSerializable("all_exercises", allExercises); mReceiver.send(STATUS_FINISHED, b); } catch (Exception e) { Log.e(TAG, "Error, could not get exercises from server: " + e.toString(), e); b.putString(Intent.EXTRA_TEXT, e.toString()); mReceiver.send(STATUS_ERROR, b); } } this.stopSelf(); }
From source file:com.phonegap.BatteryListener.java
/** * Creates a JSONObject with the current battery information * // w w w . ja v a2 s . co m * @param batteryIntent the current battery information * @return a JSONObject containing the battery status information */ 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) { Log.e(LOG_TAG, e.getMessage(), e); } return obj; }
From source file:com.app.ui.PictureSlideActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pictureslide); Intent intent = this.getIntent(); if (intent == null) { return;//w w w . ja va 2s .com } List<String> items = intent.getStringArrayListExtra("data"); int index = intent.getIntExtra("index", 0); if (items == null) { Log.v(TAG, "null++++"); finish(); return; } else { for (int i = 0; i < items.size(); i++) { Log.v(TAG, "path:" + items.get(i)); } } ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(this, items); mViewPager = (ViewPager) findViewById(R.id.viewer); mViewPager.setOffscreenPageLimit(3); mViewPager.setPageMargin(10); mViewPager.setAdapter(pagerAdapter); mViewPager.setCurrentItem(index); mPresenter = new PictureSlidePresenter(this); }
From source file:anakiou.com.picontrol.service.OutputIntentService.java
private void handleNameSet(Intent intent) { int no = intent.getIntExtra(Constants.EXTRA_NO, 0); for (Output in : outputDAO.findAll()) { if (in.getOutputNumber() == no) { String name = outputService.setOutputName(no, in.getName()); if (name.equals(in.getName())) { deliverResultToReceiver(Constants.SUCCESS_RESULT, getString(R.string.saved)); } else { deliverResultToReceiver(Constants.FAILURE_RESULT, getString(R.string.failed_to_set_name)); }/*from ww w. j ava 2s .c om*/ break; } } }
From source file:edu.uri.egr.hermes.manipulators.FileLog.java
public String battery() { IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent batteryStatus = Hermes.get().getContext().registerReceiver(null, filter); return String.valueOf(batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1 / batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) * 100)); }
From source file:anakiou.com.picontrol.service.OutputIntentService.java
private void handleSingleControl(Intent intent) { int no = intent.getIntExtra(Constants.EXTRA_NO, 0); boolean ctrlValue = intent.getBooleanExtra(Constants.EXTRA_CTRL_VALUE, false); int value = outputService.setControl(no, ctrlValue); if (value == -1) { deliverResultToReceiver(Constants.FAILURE_RESULT, getString(R.string.failed_to_send_control)); }/*from w w w. j a v a2s . co m*/ for (Output out : outputDAO.findAll()) { if (out.getOutputNumber() == no) { out.setOutputStatus(value); outputDAO.update(out); break; } } deliverResultToReceiver(Constants.SUCCESS_RESULT, getString(R.string.control_sent)); }
From source file:com.commonsware.android.andshooter.ScreenshotService.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); foregroundify();// w w w .j a va 2s . com } else if (ACTION_RECORD.equals(i.getAction())) { if (resultData != null) { startCapture(); } else { Intent ui = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(ui); } } else if (ACTION_SHUTDOWN.equals(i.getAction())) { beeper.startTone(ToneGenerator.TONE_PROP_NACK); stopForeground(true); stopSelf(); } return (START_NOT_STICKY); }
From source file:com.andrada.sitracker.tasks.receivers.UpdateStatusNotificationReceiver.java
@Override public void onReceive(@NotNull Context context, @NotNull Intent intent) { //See if there is something we can notify if (intent.getAction().equals(UpdateSuccessfulIntentMessage.SUCCESS_MESSAGE)) { int updatedAuthorsCount = intent.getIntExtra(Constants.NUMBER_OF_UPDATED_AUTHORS, 0); List<String> updatedAuthorNames = intent .getStringArrayListExtra(Constants.AUTHOR_NAMES_UPDATED_IN_SESSION); if (updatedAuthorsCount > 0) { //Notify that update successful sendNotification(updatedAuthorsCount, updatedAuthorNames, context); }/*w ww . j a v a2 s. c o m*/ } else if (intent.getAction().equals(UpdateFailedIntentMessage.FAILED_MESSAGE)) { //Notify that update failed AnalyticsHelper.getInstance().sendException(UpdateFailedIntentMessage.FAILED_MESSAGE); } }
From source file:com.bulletingroupblast.bulletingroupblast.GroupActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group); mNavigationGroupDrawerFragment = (NavigationGroupDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle();//from www .java 2 s.c o m // Set up the drawer. mNavigationGroupDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); Intent prevIntent = getIntent(); orgId = prevIntent.getIntExtra(OrganizationActivity.ORG_ID, 0); // Get the org. id groupId = prevIntent.getIntExtra(OrganizationActivity.GROUP_ID, 0); // Get the group id // Test data gs = new GlobalState(); gs.createTestData(); User curUser = gs.getCurrentUser(); Organization curOrg = curUser.getOrganizationById(orgId); // Load group data if (groupId > 0 && curOrg != null) { mGroup = curOrg.getGroupById(groupId); if (mGroup != null) { mTitle = mGroup.getName(); // Set the title } } Log.i("GA Org ID:", String.valueOf(orgId)); Log.i("GA Group ID:", String.valueOf(groupId)); }