1

I am using this library:

https://github.com/recruit-lifestyle/FloatingView

and I do all the steps, which are described in the docs.

My manifest has this permission:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> 

This is my gradle.build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "de.derdoenerdon.ressourcencockpit"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'


    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.github.OPCFoundation:UA-Java:1.03.342.0'

    //added librarys
    //pdf
    implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'
    //smiley
    implementation 'com.github.sujithkanna:smileyrating:1.6.8'
    //image picker
    implementation 'com.yanzhenjie:album:2.1.1'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    //MaterialDrawer
    implementation("com.mikepenz:materialdrawer:6.0.7@aar") {
        transitive = true
    }
    //required support lib modules
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:design:27.1.1'

    implementation "com.mikepenz:crossfader:1.5.2@aar"

    //bubbles
    implementation 'com.github.recruit-lifestyle:FloatingView:2.3.0'

    testImplementation 'junit:junit:4.12'
    testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.7'

}


apply plugin: 'com.google.gms.google-services'

This is a part of my code:

// create default notification channel
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            final String channelId = getString(R.string.name_app);
            final String channelName = getString(R.string.name_app);
            final NotificationChannel defaultChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
            final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            if (manager != null) {
                manager.createNotificationChannel(defaultChannel);
            }
        }

But I get this exception:

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@990cb01 -- permission denied for window type 2038
        at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
        at de.derdoenerdon.ressourcencockpit.library.src.main.java.jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.addViewToWindow(FloatingViewManager.java:502)
        at de.derdoenerdon.ressourcencockpit.service.ChatHeadService.onStartCommand(ChatHeadService.java:66)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3474)
        at android.app.ActivityThread.-wrap20(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

I have no idea, how I have to change my code, that this library will be useable for my application. Also the sample seems to be very complicated, for the start.

I would be happy, if someone can help me out.

Thanks in advance

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
Josi Allen
  • 137
  • 2
  • 10
  • you should put that method - addViewToWindow() here, because in this method you are getting this exception – NehaK May 07 '18 at 09:04
  • @NehaK, thanks, but how you mean? Like this? int LAYOUT_FLAG; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; } else { LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE; } WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, LAYOUT_FLAG, – Josi Allen May 07 '18 at 09:06
  • put it in question, complete method for better understanding – NehaK May 07 '18 at 09:06
  • No, this comment of me was wrong, I have no idea which addView or how to integrate it, which parameters and so on.. – Josi Allen May 07 '18 at 09:07
  • ok, the exception is occurring in library it self. – NehaK May 07 '18 at 09:08
  • Yes, thats right, and I try to fix it – Josi Allen May 07 '18 at 09:10
  • do you pass layout_flag from some where? – NehaK May 07 '18 at 09:38
  • no, I just copy the sample, means, I copy the "library" of the github project and also the ChatHead Service and the FloatingView and just start it in my application – Josi Allen May 07 '18 at 09:49
  • I would be also glad, if you can recommend me another library for this – Josi Allen May 07 '18 at 09:52
  • https://github.com/recruit-lifestyle/FloatingView/blob/master/sample/src/main/java/jp/co/recruit_lifestyle/sample/service/ChatHeadService.java here in onCommand you can see, what they did – Josi Allen May 07 '18 at 09:55
  • are you able to edit there code? try to use code as subProject-library, not by dependencies and put this code there https://stackoverflow.com/questions/49475117/android-floating-window/49475503#49475503 my answer – NehaK May 07 '18 at 10:49

0 Answers0