java - Using accelerometer code in a separate class -
hi im trying utilize different java class accelerometer usage can called class manipulate results. such doing calculations using accelerometer class object.following class not have view. have done below code completed methods when layout assigned it. please tell me how utilize accelerometer class without layout can phone call class. (i dont want utilize on create method since im not using view) give thanks
package com.example.vehiclecollisiondetection; import android.app.activity; import android.hardware.sensor; import android.hardware.sensorevent; import android.hardware.sensoreventlistener; import android.hardware.sensormanager; public class accelerometerclass extends activity implements sensoreventlistener { sensormanager sm = (sensormanager)getsystemservice(sensor_service); sensor accelerometer = sm.getdefaultsensor(sensor.type_accelerometer); sm. ide gives error here "syntax error on token, misspelled build , code hinting not observe sm. object
@override public void onsensorchanged(sensorevent event) { } @override public void onaccuracychanged(sensor sensor, int accuracy) { } } i figured out need utilize oncreate method. there anyway utilize code without layout? (calling class)
you shouldn't deriving activity. need implement sensoreventlistener , registered sensor.
java android accelerometer sensor
No comments:
Post a Comment