[Q] How to hook the step counter sensor? topic

SOCIALIZE IT ⇨

I have searched relative keyword such as `sensor` in the repo, but could not find the answer.

I want to hook the step counter's sensor to do some auto-testing jobs on a health-kit app. Basically, we could get the steps by listening the SensorManager, the demo code would be

Code:


public class StepsActivity extends Activity implements SensorEventListener {
    private SensorManager sensorManager;
    private TextView count;
    boolean activityRunning;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_steps);
        count = (TextView) findViewById(R.id.count);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        activityRunning = true;
        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
        if (countSensor != null) {
            sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI);
        } else {
            Toast.makeText(this, "Count sensor not available!", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        activityRunning = false;
    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        if (activityRunning) {
            count.setText(String.valueOf(event.values[0]));
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }
}


I've read the tutorial, I know we could hook a specific function in a specific class, such as

Code:


        findAndHookMethod("com.android.systemui.statusbar.policy.Clock", lpparam.classLoader, "updateClock", new XC_MethodHook() {

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                TextView tv = (TextView) param.thisObject;
                String text = tv.getText().toString();
                tv.setText("time is:"+text);
                tv.setTextColor(Color.RED);
            }
        });


But I'm wondering how to hook the data on system sensor?

xda-developers


  1. No brightness sensor / rotation topic
  2. [Q] G Sensor broken topic
  3. Proximity sensor ? topic
  4. [Q] [Request] Cover sensor for screen topic
  5. Proximity sensor not working properly topic
  6. Ambient Sensor topic
  7. Unlock LTE bands step by step - XIaomi Mi Note specific topic
  8. Step by step - Sense to GPE? topic
  9. How to set JAVA path Permanently[Step By Step] topic
  10. [Q] How to hook the step counter sensor? topic
  11. [Q] SU Command from hook topic
  12. [Q] call startService from hook method topic
  13. [Q] Hook and run outside topic
  14. Is root required to roll back to KitKat? topic
  15. [REQ] Multi DPI Stock Camera topic
  16. May be this is it for Xperia J topic
  17. [Q] No IMEI and baseband anymore. So back to stock rom for repair! topic
  18. [Q] New to phone - on 24A rooted - where to go from here? topic
  19. Htc desire 816 official lollipop update video review topic
  20. [Q] Galaxy S6 Edge T-Mobile Unlock by SIM code topic

0 commentaires:

Enregistrer un commentaire