Giter Site home page Giter Site logo

Crash on Android 6+ about magnet HOT 3 CLOSED

premnirmal avatar premnirmal commented on July 20, 2024
Crash on Android 6+

from magnet.

Comments (3)

premnirmal avatar premnirmal commented on July 20, 2024

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.

premnirmal avatar premnirmal commented on July 20, 2024

See the updated README

from magnet.

priyankagb avatar priyankagb commented on July 20, 2024

@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

Screenshot from 2020-02-27 15-52-25

from magnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.