0

I have an accessibility service and I want to use it to get the resolution (width and height) of any app the user currently has opened. I don't mean the max resolution of the device I mean the resolution the foreground app is running in which can be lower than the max resolution of the device.

Please I've been stuck on this forever. I tried this but it doesn't work:

WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Point size = new Point();
windowManager.getDefaultDisplay().getSize(size);

getSize() when called from a service context will always return the max resolution of the device. What else can I try?

purchaseTest
  • 524
  • 3
  • 15
  • What do you mean by "the app resolution can be lower than the max resolution". I've never seen an app, which let's you set a custom resolution. You said width and height, so do you mean split screen applications? Also, you said "of any app the user has opened", which is definitely not possible. Your app does not know about width and height of other apps. – nulldroid Apr 26 '21 at 18:00
  • @Nulldroid there are many ways to force apps to use a custom resolution, including built-in ways like in some Samsung phones and in gaming phones. Also some apps that are not designed to stretch and fit whatever display will just show black bars on both sides instead. – purchaseTest Apr 26 '21 at 18:05
  • for your app only you can use: https://stackoverflow.com/questions/13654861/how-can-i-get-the-size-of-the-android-application-window-and-not-the-physical-sc – nulldroid Apr 26 '21 at 18:10
  • @Nulldroid thanks but I need it only for other apps. What about the fact that this is an accessibility service that I'm using? I'm already using it to retrieve information about any view on the display so surely it can get the resolution? – purchaseTest Apr 26 '21 at 18:16
  • 1
    Sorry, I'm not familiar with accessibility services. But if an AccessibilityEvent occurs and you have the correct permission like android:canRetrieveWindowContent="true", i think it's possible. Something like event.getSource().getRootView().width()/.height() Please see https://developer.android.com/guide/topics/ui/accessibility/service#window-change-events – nulldroid Apr 26 '21 at 18:29
  • or something like window.decorView.height.toFloat() hope this helps – nulldroid Apr 26 '21 at 18:34
  • can't find anything related to height and width – purchaseTest Apr 26 '21 at 18:37
  • I'm not sure what this `getBoundsInScreen()` method does but it sounds promising doesn't it? https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#getBoundsInScreen(android.graphics.Rect) – purchaseTest Apr 26 '21 at 19:06
  • Forgot the @Nulldroid – purchaseTest Apr 26 '21 at 19:11
  • @Nulldroid any ideas? – purchaseTest Apr 26 '21 at 21:20

0 Answers0