Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception using non activity context initialising mixpanel #850

Open
warting opened this issue Dec 18, 2024 · 0 comments · May be fixed by #851
Open

Exception using non activity context initialising mixpanel #850

warting opened this issue Dec 18, 2024 · 0 comments · May be fixed by #851

Comments

@warting
Copy link

warting commented Dec 18, 2024

We are using version 8.0.1 and we get this errors in logcat when initializing mixpanel.

We initialize mixpanel in hilt using application context (no visual content) we need mixpanel in background work broadcast receivers etc and won't have a WindowManager at all times.

mixpanel tries to access display with the following code:

Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

(getDefaultDisplay is deprecated btw)

I would suggest to use displaymanager to get the default display instead of WindowManager:

val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val display: Display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)

Stacktrace:

 Tried to access visual service WindowManager from a non-visual Context:xxx.xxx.xxx WindowManager should be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen. (Ask Gemini)
    java.lang.IllegalAccessException: Tried to access visual service WindowManager from a non-visual Context:xxx.xxx.xxx@fed68d3
        at android.app.ContextImpl.getSystemService(ContextImpl.java:2115)
        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:900)
        at com.mixpanel.android.mpmetrics.SystemInformation.<init>(SystemInformation.java:91)
        at com.mixpanel.android.mpmetrics.SystemInformation.getInstance(SystemInformation.java:34)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages$Worker$AnalyticsMessageHandler.<init>(AnalyticsMessages.java:361)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages$Worker.restartWorkerThread(AnalyticsMessages.java:354)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages$Worker.<init>(AnalyticsMessages.java:329)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages.createWorker(AnalyticsMessages.java:52)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages.<init>(AnalyticsMessages.java:47)
        at com.mixpanel.android.mpmetrics.AnalyticsMessages.getInstance(AnalyticsMessages.java:71)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.getAnalyticsMessages(MixpanelAPI.java:1706)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.<init>(MixpanelAPI.java:156)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.<init>(MixpanelAPI.java:122)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance(MixpanelAPI.java:466)
        at com.mixpanel.android.mpmetrics.MixpanelAPI.getInstance(MixpanelAPI.java:239)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant