Re: [android-developers] Android Accelerometer Sensor
And what is the error? 2011/7/7 souissi haythem > Hi, > > I am trying to work with Accelerometer Sensor. So i tried this > example: > http://blog.androgames.net/85/android-accelerometer-tutorial/ > > It work perfectly. > But when i change AccelerometerManager activity to a service, it > doesn't work and i got an error. > > //this is the activity that i want change > public class Accelerometer extends Activity >implements AccelerometerListener { > >private static Context CONTEXT; > >/** Called when the activity is first created. */ >@Override >public void onCreate(Bundle savedInstanceState) { >super.onCreate(savedInstanceState); >setContentView(R.layout.main); >CONTEXT = this; >} > >protected void onResume() { >super.onResume(); >if (AccelerometerManager.isSupported()) { >AccelerometerManager.startListening(this); >} >} > >protected void onDestroy() { >super.onDestroy(); >if (AccelerometerManager.isListening()) { >AccelerometerManager.stopListening(); >} > >} > >public static Context getContext() { >return CONTEXT; >} > >/** > * onShake callback > */ >public void onShake(float force) { >Toast.makeText(this, "Phone shaked : " + force, 1000).show(); >} > >/** > * onAccelerationChanged callback > */ >public void onAccelerationChanged(float x, float y, float z) { >((TextView) findViewById(R.id.x)).setText(String.valueOf(x)); >((TextView) findViewById(R.id.y)).setText(String.valueOf(y)); >((TextView) findViewById(R.id.z)).setText(String.valueOf(z)); >} > > } > > //this is my service when i change it, my error is hir > public class Accelerometer extends Service implements > AccelerometerListener{ > private static Context CONTEXT; > > @Override > public IBinder onBind(Intent intent) { > // TODO Put your code here > return null; > } > > @Override > public void onCreate() { > System.out.println(”start listening”); > // if (AccelerometerManager.isSupported()) { > AccelerometerManager.startListening(this); > > // } > } > > @Override > public void onDestroy() { > System.out.println(”start listening”); > // if (AccelerometerManager.isListening()) { > AccelerometerManager.stopListening(); > // } > } > > public static Context getContext() { > return CONTEXT; > } > > /** > * onShake callback > */ > public void onShake(float force) { > Toast.makeText(this, “Phone shaked niktilha omha ya 3ammi el7ag: ” + > force, 1000).show(); > } > > /** > * onAccelerationChanged callback > */ > public void onAccelerationChanged(float x, float y, float z) { > System.out.println(”x = “+x+” y = “+y+” z = “+z); > } > > } > > Thanks for help. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Android Accelerometer Sensor
Well could you post the error? Also did you change the activity declaration in your manifest to declare a service? The class you posted is also extending activity, not service. On Thu, Jul 7, 2011 at 2:35 PM, souissi haythem wrote: > Hi, > > I am trying to work with Accelerometer Sensor. So i tried this > example: > http://blog.androgames.net/85/android-accelerometer-tutorial/ > > It work perfectly. > But when i change AccelerometerManager activity to a service, it > doesn't work and i got an error. > > //this is the activity that i want change > public class Accelerometer extends Activity >implements AccelerometerListener { > >private static Context CONTEXT; > >/** Called when the activity is first created. */ >@Override >public void onCreate(Bundle savedInstanceState) { >super.onCreate(savedInstanceState); >setContentView(R.layout.main); >CONTEXT = this; >} > >protected void onResume() { >super.onResume(); >if (AccelerometerManager.isSupported()) { >AccelerometerManager.startListening(this); >} >} > >protected void onDestroy() { >super.onDestroy(); >if (AccelerometerManager.isListening()) { >AccelerometerManager.stopListening(); >} > >} > >public static Context getContext() { >return CONTEXT; >} > >/** > * onShake callback > */ >public void onShake(float force) { >Toast.makeText(this, "Phone shaked : " + force, 1000).show(); >} > >/** > * onAccelerationChanged callback > */ >public void onAccelerationChanged(float x, float y, float z) { >((TextView) findViewById(R.id.x)).setText(String.valueOf(x)); >((TextView) findViewById(R.id.y)).setText(String.valueOf(y)); >((TextView) findViewById(R.id.z)).setText(String.valueOf(z)); >} > > } > > //this is my service when i change it, my error is hir > public class Accelerometer extends Service implements > AccelerometerListener{ > private static Context CONTEXT; > > @Override > public IBinder onBind(Intent intent) { > // TODO Put your code here > return null; > } > > @Override > public void onCreate() { > System.out.println(”start listening”); > // if (AccelerometerManager.isSupported()) { > AccelerometerManager.startListening(this); > > // } > } > > @Override > public void onDestroy() { > System.out.println(”start listening”); > // if (AccelerometerManager.isListening()) { > AccelerometerManager.stopListening(); > // } > } > > public static Context getContext() { > return CONTEXT; > } > > /** > * onShake callback > */ > public void onShake(float force) { > Toast.makeText(this, “Phone shaked niktilha omha ya 3ammi el7ag: ” + > force, 1000).show(); > } > > /** > * onAccelerationChanged callback > */ > public void onAccelerationChanged(float x, float y, float z) { > System.out.println(”x = “+x+” y = “+y+” z = “+z); > } > > } > > Thanks for help. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Raghav Sood http://www.raghavsood.com/ http://www.androidappcheck.com/ http://www.telstop.tel/ -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Android Accelerometer Sensor
Hi, I am trying to work with Accelerometer Sensor. So i tried this example: http://blog.androgames.net/85/android-accelerometer-tutorial/ It work perfectly. But when i change AccelerometerManager activity to a service, it doesn't work and i got an error. //this is the activity that i want change public class Accelerometer extends Activity implements AccelerometerListener { private static Context CONTEXT; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CONTEXT = this; } protected void onResume() { super.onResume(); if (AccelerometerManager.isSupported()) { AccelerometerManager.startListening(this); } } protected void onDestroy() { super.onDestroy(); if (AccelerometerManager.isListening()) { AccelerometerManager.stopListening(); } } public static Context getContext() { return CONTEXT; } /** * onShake callback */ public void onShake(float force) { Toast.makeText(this, "Phone shaked : " + force, 1000).show(); } /** * onAccelerationChanged callback */ public void onAccelerationChanged(float x, float y, float z) { ((TextView) findViewById(R.id.x)).setText(String.valueOf(x)); ((TextView) findViewById(R.id.y)).setText(String.valueOf(y)); ((TextView) findViewById(R.id.z)).setText(String.valueOf(z)); } } //this is my service when i change it, my error is hir public class Accelerometer extends Service implements AccelerometerListener{ private static Context CONTEXT; @Override public IBinder onBind(Intent intent) { // TODO Put your code here return null; } @Override public void onCreate() { System.out.println(”start listening”); // if (AccelerometerManager.isSupported()) { AccelerometerManager.startListening(this); // } } @Override public void onDestroy() { System.out.println(”start listening”); // if (AccelerometerManager.isListening()) { AccelerometerManager.stopListening(); // } } public static Context getContext() { return CONTEXT; } /** * onShake callback */ public void onShake(float force) { Toast.makeText(this, “Phone shaked niktilha omha ya 3ammi el7ag: ” + force, 1000).show(); } /** * onAccelerationChanged callback */ public void onAccelerationChanged(float x, float y, float z) { System.out.println(”x = “+x+” y = “+y+” z = “+z); } } Thanks for help. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Android Accelerometer Sensor output.
Hi, I am not able to get whether phone is tilted right / left or from top up / bottom up! I am trying to use Accelerometer sensor but output is very difficult to interpret! Any suggestions / document so that I can know tilt position of phone? Thanks, -A -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en