Comments (3)
You need to request the permission at runtime on android 6+
public void checkDrawOverlayPermission() {
if (!Settings.canDrawOverlays(Context)) {
final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
// continue here - permission was granted
}
}
}
from magnet.
See the updated README
from magnet.
@premnirmal I do the same still getting this error
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
//If the draw over permission is not available open the settings screen to grant the permission.
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, DRAW_OVER_OTHER_APP_PERMISSION);
} else {
startFloatingOverLayService();
}
private void startFloatingOverLayService() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (!isMyFloatingServiceRunning()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startForegroundService(new Intent(mActivity, FloatingOverlayViewService.class));
else
startService(new Intent(mActivity, FloatingOverlayViewService.class));
} else if (FloatingOverlayViewService.getInstance() != null) {
//do stuff....
}
}
}
is there any other issue with this?
here is crash log
Fatal Exception: java.lang.RuntimeException
Unable to create service com.app.nw.screenshot.services.FloatingOverlayViewService: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@3c07205 -- permission denied for window type 2038
android.app.ActivityThread.handleCreateService (ActivityThread.java:3775)
android.app.ActivityThread.access$1400 (ActivityThread.java:237)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1808)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:214)
android.app.ActivityThread.main (ActivityThread.java:7063)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
Caused by android.view.WindowManager$BadTokenException
Unable to add window android.view.ViewRootImpl$W@3c07205 -- permission denied for window type 2038
android.view.ViewRootImpl.setView (ViewRootImpl.java:1080)
android.view.WindowManagerImpl.addView (WindowManagerImpl.java:93)
com.app.nw.screenshot.magnetanimation.Magnet.addToWindow (Magnet.java:330)
com.app.nw.screenshot.magnetanimation.Magnet.show (Magnet.java:380)
com.app.nw.screenshot.services.FloatingOverlayViewService.onCreate (FloatingOverlayViewService.java:161)
android.app.ActivityThread.handleCreateService (ActivityThread.java:3763)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
here are layout params for window
int overlayFlag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
overlayFlag = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
overlayFlag = WindowManager.LayoutParams.TYPE_PHONE;
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
iconWidth > 0 ? iconWidth : WindowManager.LayoutParams.WRAP_CONTENT,
iconHeight > 0 ? iconHeight : WindowManager.LayoutParams.WRAP_CONTENT,
overlayFlag,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSPARENT);
params.gravity = Gravity.TOP | Gravity.START;
windowManager.addView(iconView, layoutParams = params);
Please help to solve this. This crash is 100% in samsung device which have version 9 and devices are this
from magnet.
Related Issues (20)
- Unit Tests for improved test coverage HOT 1
- NullPointerException HOT 6
- Size of magnet HOT 5
- [Compilation Error] Unresolved reference: newBuilder HOT 3
- Demo not working HOT 1
- Attempting to destroy the window while drawing! HOT 2
- Magnet used in Service crashes after second removing of magnet isntance HOT 1
- App crashes on Android Oreo while showing a magnet HOT 1
- Application not usable once user clicks on Magnet HOT 1
- How to set position for Magnet without the animation? HOT 3
- Android P support
- Destroy current visible magnet HOT 6
- java.lang.IllegalArgumentException: View=android.widget.FrameLayout{e3fb200 V.E...C.. ......I. 0,0-210,210} not attached to window manager
- NullPointerException
- Cannot set initial position on right side because of spring effect HOT 1
- How to set start position HOT 3
- Stick to wall horizontal only HOT 8
- uses-sdk element cannot have a "tools:node" attribute HOT 2
- Min SDK ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magnet.