Nothing-Developer-Programme / Glyph-Developer-Kit

455 stars 26 forks source link

Glyph SDK not working on reboot #12

Open Fr4nKB opened 1 month ago

Fr4nKB commented 1 month ago

I have a NotificationListenerService and turn on some glpyhs when a notification is received. My code works when the app is installed for the first time but when the phone reboots glyphs won't turn on until I eliminate app data or reinstall the app.

This is part of the code I'm referring to

for(i in 1 until (wakeLockTime / (GLYPH_DEFAULT_INTESITY * delay / step + delayBetweenAnimation))) {
    for (light in GLYPH_DEFAULT_INTESITY downTo 0 step 100) {
        framePulse = frameStatic
        activeZonesPulse.forEach { zone ->
            framePulse = framePulse.buildChannel(zone, light)
        }
        mGM.toggle(framePulse.build())
        delay(25)
    }
    delay(4000)
}

Any suggestions?

Gab1er commented 1 month ago

I'm not an expert, but does your application start automatically when the smartphone starts and does the listening service also start a that time?

Fr4nKB commented 1 month ago

Yes, a NotificationListenerService starts automatically at boot without using any BroadcastReceiver. Using some logging I can confirm that the code I posted above is reached but the Glyphs don't turn on.

I narrowed it down to profileInstalled file in the app's file directory, eliminating that and restarting the app makes it works (a simple restart won't work)

Gab1er commented 1 month ago

Perfect, so I think we can mark this issue as closed?

Fr4nKB commented 1 month ago

For anyone in need for a solution, delay the initialization of the GDK by some seconds

override fun onCreate() {
        super.onCreate()
        Handler(Looper.getMainLooper()).postDelayed({
            init()
            val localGM = GlyphManager.getInstance(applicationContext)
            localGM?.init(mCallback)
            mGM = localGM
        }, 3 * 1000)
}