txusballesteros / bubbles-for-android

Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.
Apache License 2.0
1.48k stars 281 forks source link

android O new issue #39

Open NullPoint-A opened 7 years ago

NullPoint-A commented 7 years ago

android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@2557df6 -- permission denied for window type 2006 at android.view.ViewRootImpl.setView(ViewRootImpl.java:789) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92) at com.txusballesteros.bubbles.BubblesService$2.run(BubblesService.java:120) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

app targetSdkVersion 26

help me.. T.T

xiaoxuanwang commented 7 years ago

For android API > 22, it need the users' permission to allow the app to put on top of other apps. For API <=22, the system grant the permission automatically.

NullPoint-A commented 6 years ago

TYPE_PHONE, TYPE_SYSTEM_OVERLAY can not be used when targeting OREO. Use TYPE_APPLICATION_OVERLAY instead. need to change the library.

BubblesService.java -> buildLayoutParamsForBubble() , buildLayoutParamsForTrash()

NullPoint-A commented 6 years ago

https://developer.android.com/about/versions/oreo/android-8.0-changes.html#all-aw

fifisamy commented 6 years ago

ihave this problem also with android o what is the solution

SpamhaterAlex commented 6 years ago

I have the same problem.

SpamhaterAlex commented 6 years ago

I suppose the only way is to override the methods, but dont know, how to implement them

jwgibanez commented 6 years ago

I am also having the same issue. Has anyone found a viable solution?

lxknvlk commented 6 years ago

Same problem here. BubblesManager initialization crashes app, despite having needed permission and Settings.canDrawOverlays(getApplicationContext()) returns true

harmskhosa commented 6 years ago

If I'm not mistaken, @NullPoint-A comment is the best solution. The library needs to be updated to use TYPE_APPLICATION_OVERLAY instead when setting the params for each layout (the bubble and the trash). But this change seems pretty simple. For example, for the bubble, the new code in the BubblesService class should look like:

private WindowManager.LayoutParams buildLayoutParamsForBubble(int x, int y) {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams. TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSPARENT);
        params.gravity = Gravity.TOP | Gravity.START;
        params.x = x;
        params.y = y;
        return params;
    }

I'll send a pull request if I have time...

appspell commented 6 years ago

Please check this out https://github.com/txusballesteros/bubbles-for-android/pull/47

harmskhosa commented 6 years ago

@appspell lgtm

MyCentreBucket commented 5 years ago

This worked for me.

final WindowManager.LayoutParams myParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                PixelFormat.TRANSLUCENT
        );

        if (Build.VERSION.SDK_INT >= 23) {
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                startActivity(intent);
                return;
            } else {
                WindowManager windowManager = getWindowManager();
                windowManager.addView(bubbleView, myParams);
            }
        } else {
            WindowManager windowManager = getWindowManager();
            windowManager.addView(bubbleView, myParams);
        }