Reputation: 3873
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:
Remove esfile explorer
https://android.stackexchange.com/questions/148260/screen-overlay-detected-what-is-the-problem
https://www.howtogeek.com/271519/how-to-fix-the-screen-overlay-detected-error-on-android/
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
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