Androider
Androider

Reputation: 3873

Screen Overlay Detected Android

I found the below issue of Screen Overlay detected when click permission in Motog3 marshmallow mobile.

i found many solution over internet search everywhere, you can check below:

  1. Remove esfile explorer

  2. https://www.youtube.com/watch?v=QHidevTDrYI

  3. Screen overlay detected blocks Android permissions

  4. https://android.stackexchange.com/questions/148260/screen-overlay-detected-what-is-the-problem

  5. https://forums.androidcentral.com/android-6-0-marshmallow/682802-screen-overlay-detected-what-can-i-do.html

  6. https://www.howtogeek.com/271519/how-to-fix-the-screen-overlay-detected-error-on-android/

  7. https://github.com/MohammadAdib/Roundr/issues/10

  8. Android marshmallow : Galaxy Note 4 Screen Overlay Detected

etc. many more.

If i don't call permission below then no problem.

Therefore if anyone want to give the best solution then please share.

Please before mentioning it duplicate, i want proper solution for it.

Feel free to ask any information or code i'm sharing some code also.

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.psm">
<!---->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/MyMaterialTheme">
        <activity android:name=".MainActivity"
            android:screenOrientation="portrait">

        </activity>
        <activity android:name=".SplashScreen"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.nippon.registration.Registration"
           ></activity>
    </application>

</manifest>

Permission code in Mainactivity.java

checkAndRequestPermissions(); //called in oncreate() of activity


   private boolean checkAndRequestPermissions() {
        try {
            int permissionWriteEXTERNALSTORAGE = ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
            int PermissionCamera = ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA);


            List<String> listPermissionsNeeded = new ArrayList<>();

            if (permissionWriteEXTERNALSTORAGE != PackageManager.PERMISSION_GRANTED) {
                listPermissionsNeeded.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
            }
            if (PermissionCamera != PackageManager.PERMISSION_GRANTED) {
                listPermissionsNeeded.add(android.Manifest.permission.CAMERA);
            }
            if (!listPermissionsNeeded.isEmpty()) {
                ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 1);
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

Thanks in advance, for perfect solution.

Upvotes: 0

Views: 541

Answers (1)

Androider
Androider

Reputation: 3873

finally i got solution for above problem of Screen Overlay Detected by removing below code which i was using for testing memory usage in app:

final Runtime runtime = Runtime.getRuntime();
        final long usedMemInMB=(runtime.totalMemory() - runtime.freeMemory()) / 1048576L;
        final long maxHeapSizeInMB=runtime.maxMemory() / 1048576L;
        final long availHeapSizeInMB = maxHeapSizeInMB - usedMemInMB;
        Toast.makeText(getApplicationContext(),String.valueOf(usedMemInMB+"  "+ maxHeapSizeInMB+" "+ availHeapSizeInMB), Toast.LENGTH_LONG).show();

Thanks for everyone support!

Upvotes: 1

Related Questions