Git Product home page Git Product logo

Comments (3)

kargoolek avatar kargoolek commented on May 24, 2024

OK, working after changing:

compileSdkVersion 26 buildToolsVersion "26.0.0"

to:

compileSdkVersion 25 buildToolsVersion "25.0.0"

from android-samples.

kevalpatel2106 avatar kevalpatel2106 commented on May 24, 2024

@kargoolek This may be due to background service changes applied in android O. You cannot make service forground directly after issuing startService() command. Use NotificationManager.startServiceInForeground() to create foreground service. More on that here.

from android-samples.

yfujiki avatar yfujiki commented on May 24, 2024

Hello @kevalpatel2106. Thanks for great repo and a write up in Medium.

I just stumbled on the same issue and figured out that the true cause was very simple.

WindowManager.LayoutParams.TYPE_PHONE is deprecated in SDKVersion 26 and up, that's why it's crashing for Oreo and up, and that's why lowering SDK build version works as well.

So, changing the LayoutParams initialization to this made it work for all environments with latest SDK.

        final WindowManager.LayoutParams params;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            //Add the view to the window.
            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
        } else {
            //Add the view to the window.
            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
        }

Hope this helps somebody else!

from android-samples.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.