SensorEventListener not working in Android 1.5????

Put your problem here if it does not fit any of the other categories.

SensorEventListener not working in Android 1.5????

Postby psdeepti » Thu Oct 15, 2009 4:38 pm

Here is my code:

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.Toast;

public class ShakeSample extends Activity implements SensorEventListener {

private SensorManager sensorMgr;



@Override
public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

sensorMgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor accSensor = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
sensorMgr.registerListener(this, accSensor, SensorManager.SENSOR_DELAY_GAME);


}

protected void onStop() {

super.onStop();
sensorMgr.unregisterListener(this);
}

@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub

}

@Override
public void onSensorChanged(SensorEvent event)
{

Toast.makeText(getApplicationContext(), "jklj", 10000);
}

}


Manifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ShakeSample"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ShakeSample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="3" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

</manifest>



OnSensorChanged() function is not called as and Toast is not displayed on scren.The screen is completely blank.

Whats wrong with my code??why doesnt it work on my HTC Magic??

Am I missing any permissions???

Someone help me please.

Thanks
Deepti
psdeepti
Freshman
Freshman
 
Posts: 9
Joined: Thu Oct 15, 2009 4:32 pm

Top

Postby chimaera » Thu Oct 15, 2009 9:06 pm

The problem is that you have to show your toast:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Toast.makeText(getApplicationContext(), "jklj", 10000).show()
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Use Log.d it's better to log debug...
chimaera
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jun 19, 2009 1:42 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 10 guests