Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Accelerometer Sensor
    primarykey
    data
    text
    <p>I am trying to work with Accelerometer Sensor. So i tried this example: <a href="http://blog.androgames.net/85/android-accelerometer-tutorial/" rel="nofollow">http://blog.androgames.net/85/android-accelerometer-tutorial/</a></p> <p>It work perfectly. But when i change AccelerometerManager activity to a service, it doesn't work and i got an error.</p> <pre><code>//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)); } } </code></pre> <p>//this is my service when i change it, my error is hir public </p> <pre><code>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); } } </code></pre> <p>Thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload