Back to project page jsense-collector.
The source code is released under:
MIT License
If you think the Android project jsense-collector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.jsense.collector; // w ww . j a v a2s . co m import android.app.ActivityManager; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.CompoundButton; import android.widget.ToggleButton; import com.google.inject.Inject; import roboguice.activity.RoboActivity; import roboguice.inject.InjectView; public class MainActivity extends RoboActivity { @InjectView(R.id.startSensingButton) ToggleButton startSensingButton; @Inject ActivityManager activityManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startSensingButton.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Intent service = new Intent(MainActivity.this, SensingService.class); if (isChecked) { startService(service); } else { stopService(service); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private boolean isSensingServiceRunning() { for (ActivityManager.RunningServiceInfo service : activityManager.getRunningServices(Integer.MAX_VALUE)) { if (SensingService.class.getName().equals(service.service.getClassName())) { return true; } } return false; } }