Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asking for permission before starting a download session with download manager brings "Screen overlay detected" screen on Samsung Devices (Tested with s6 and s7) #18

Open
roostaamir opened this issue Dec 15, 2016 · 1 comment

Comments

@roostaamir
Copy link

When I try to ask for "WRITE_EXTERNAL_STORAGE" before I initiate a download session using the built-in download manager, the "screen overlay detected" message shows up. Look at the code below:

@AskPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    private void downloadFile() {
        String downloadDir = "/photo";
        File direct = new File(Environment.getExternalStorageDirectory()
                + downloadDir);
        if (!direct.exists())
            direct.mkdirs();

        String fileExtension = ".jpg";
        String filename = name;

        DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
        request.setTitle("title");
        request.setDescription("downloading...");
        request.setDestinationInExternalPublicDir(downloadDir,
                filename + fileExtension);
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        downloadManager.enqueue(request);
        Toast toast = Toast.makeText(getActivity(), "download started", Toast.LENGTH_LONG);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "RoyaBold.ttf"));
        toast.show();
    }

If you play with the screen and deny the permission one time, and dismiss the "screen overlay detected" dialog, I can then grant the permission. Strangely if I go to settings, disable the permission, and run this method again, it will bring the permission dialog successfully this time (without showing the screen overlay detected dialog)

What is the problem?

@canelmas
Copy link
Owner

canelmas commented Dec 18, 2016

Hi @roostaamir, not sure if this is related to let library or the specific permission you're asking.

Can you please check this and this

It seems that you already have an app on your phone with SYSTEM_ALERT_WINDOW permission granted and it's using a screen overlay while you're trying to request WRITE_EXTERNAL_STORAGE permission within your app. And the system does not allow it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants