canelmas / let

Annotation based simple API flavored with AOP to handle new Android runtime permission model
Apache License 2.0
530 stars 40 forks source link

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 7 years ago

roostaamir commented 7 years ago

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 commented 7 years ago

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.