首页 > 解决方案 > 启用添加窗口 android.view.ViewRootImpl$W@990cb01 -- 窗口类型 2038 的权限被拒绝

问题描述

我正在使用这个库:

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

我完成了文档中描述的所有步骤。

我的清单有这个permission

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

这是我的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'

这是我的代码的一部分:

// 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);
            }
        }

但我得到了这个例外:

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) 

我不知道我必须如何更改我的代码,这个库是否可以用于我的应用程序。开始时,样本似乎也很复杂。

如果有人可以帮助我,我会很高兴。

提前致谢

标签: androidandroid-layoutandroid-fragments

解决方案


推荐阅读