jmp-12 / SuperToasts

A library that extends the Android toast framework.
Apache License 2.0
2.67k stars 499 forks source link

API 28 Exception: Unable to add window -- token null is not valid; #123

Open 1371030 opened 6 years ago

1371030 commented 6 years ago

API 28 Exception: Unable to add window -- token null is not valid; is your activity running?

ghost commented 5 years ago

Hello, I got the same problem[

HEZI0427 commented 5 years ago

API 28 Exception: Unable to add window -- token null is not valid; is your activity running?

Step 1 : replace SuperToast WindowManager.LayoutParams.TYPE_TOAST by WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY

Step 2 : request android.permission.SYSTEM_ALERT_WINDOW permission runtime if (Build.VERSION.SDK_INT >= 23) { if (!Settings.canDrawOverlays(getApplicationContext())) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, 10); return; } }

Dovar66 commented 5 years ago

you can refer to https://github.com/Dovar66/DToast

Behrouz-m commented 5 years ago

use this + overlay permission

(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
                             WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
                             WindowManager.LayoutParams.TYPE_PHONE)
fatemi2020 commented 2 years ago

Salam, In my case, the issue was resolved after replace SuperToast with SuperActivityToast