I want to log an event for telemetry when user zooms in the screen of an app in android. Based on my research I could not find a system event that I can subscribe to determine if user zoomed the screen. Any pointers to detect that?
Asked
Active
Viewed 514 times
1
-
https://stackoverflow.com/questions/5705923/how-to-detect-the-pinch-zoom-event-with-ongesturelistener-in-android – BerkZerker707 Jul 05 '20 at 18:50
-
There is no single definition of "zooms the screen". And there is no single trigger mechanism for any particular UI operation. Those things are defined by the app, not the system, and so there will not be a system event for you to find out when "user zooms in the screen of an app". – CommonsWare Jul 05 '20 at 19:05
2 Answers
1
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.accessibilityservice.AccessibilityService;
import android.graphics.Region;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity implements AccessibilityService.MagnificationController.OnMagnificationChangedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onMagnificationChanged(@NonNull AccessibilityService.MagnificationController magnificationController, @NonNull Region region, float v, float v1, float v2) {
float Scale = v;
// Scale will be changed as magnification is done on app
}
}

Anique Azhar
- 51
- 6
-
Tried this but it did not work. By the way I triple tap to zoom the screen and though I see the app screen zooming in, the onMagnificationChanged method was not called. Would this work even with triple tap. I do not see any other way to zoom the screen except of triple tap in android. – Reshma Jul 05 '20 at 19:49
-
You will need to configure AccessibilityService, connect it & then add listener. Hopefully it will work. For reference you can check this GitHub Repo [https://github.com/SergeyBurlaka/MyAccessibilityService] – Anique Azhar Jul 05 '20 at 20:09
0
You are looking for Android Gestures
Here is a documentation about it: https://developer.android.com/training/gestures
Here is a zoom/scale gesture: https://developer.android.com/training/gestures/scale
and
Can we use scale gesture detector for pinch zoom in Android?

xszym
- 928
- 1
- 5
- 11