Skip to content

Commit

Permalink
Merge pull request #27 from gbumps/release/0.3.0
Browse files Browse the repository at this point in the history
fix: fix crash background on Android
  • Loading branch information
gbumps committed Oct 24, 2023
2 parents 114023f + 381e40d commit f41682f
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions android/src/main/java/com/screenguard/ScreenGuardModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,12 @@ public void activateShield(String hexColor) {
mHandlerBlockScreenShot = new Handler(Looper.getMainLooper());
}
mHandlerBlockScreenShot.post(() -> Objects.requireNonNull(
currentReactContext.getCurrentActivity()
getReactApplicationContext().getCurrentActivity()
).getWindow().setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
));
//TODO: Build another approach for Android 12+, as system blocks behaviour of activity which
//contains flag FLAG_NOT_TOUCHABLE, that mean keyboard or other gestures on main React Native
//app will not work correctly.
// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
// Intent intent = new Intent(
// currentReactContext.getCurrentActivity(),
// ScreenGuardColorActivity.class
// );
// intent.putExtra("background", hexColor);
// intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
// Objects.requireNonNull(
// currentReactContext.getCurrentActivity()).startActivity(intent);
// }

} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -106,24 +94,15 @@ public void activateWithoutShield() {
}
}

@ReactMethod
@ReactMethod
public void deactivateShield() {
try {
// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
// currentReactContext.sendBroadcast(
// new Intent("com.screenguard.ScreenGuardColorActivity.close")
// );
// }
Handler handler = new Handler();
Runnable delayedFunction = () -> {
if (mHandlerBlockScreenShot != null) {
mHandlerBlockScreenShot.post(() -> Objects.requireNonNull(
currentReactContext.getCurrentActivity()
).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE));
if (mHandlerBlockScreenShot != null) {
mHandlerBlockScreenShot.post(() -> Objects.requireNonNull(
getReactApplicationContext().getCurrentActivity()
).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE));
mHandlerBlockScreenShot = null;
}
};
handler.postDelayed(delayedFunction, 500);
}
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit f41682f

Please sign in to comment.