简体   繁体   中英

TYPE_STEP_COUNTER cannot be resolved or is not a field Android KitKat

I'm trying to develop a Step Counter app using the KitKat SDK. But I keep getting this error and the Sensor class does not have TYPE_STEP_COUNTER in it.

Can someone please help me identify the issue?

Update: Adding the code here:

   mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mStepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
    mStepDetector = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
    mUiHandler = new Handler(Looper.getMainLooper());

I have solved the problem using the int value of the Sensor.TYPE_STEP_DETECTOR instead of the constant itself; the value is '18'. All other attempts don't work, I have updated sdk and use the target 19.

You should update your SDK and change the target SDK to 19 from the manifest

and change the project sdk at first create because this feature is added only in kitkat 19 API

I agree with what @Dark has to say. This sensors are added in Android API Level 19 with KitKat OS Version.You need to change the Target SDK version in your Application Manifest file as below.

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19"/>

Please also do try to do the following if it is not set to API LEVEL 19.

1) Right click on your project in the package explorer.
2) Click on Properties(Second Last option).
3) Go to Android in the window that opens.
4) Change project Build Target values to "Target : Android 4.4.2", "Platform : 4.4.2" and "API Level : 19"
5) Apply , OK and you should be set to use TYPE_STEP COUNTER and TYPE_STEP_DETECTOR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM