Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29593

How to blur or add overlay to hide ReactActivity when app is in Recent View on Android devices?

$
0
0

When the app is in recent view or background, I need to hide the sensitive information on the current React Native app.

I've tried to use FLAG_SECURE flag to add an overlay to the app. However, it does not work on Android 7.

In MainActivity.java:

package com.awesomeproject;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "AwesomeProject";
  }

   @Override
    protected void onPause() {
        super.onPause();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);

        this.addContentView(); //??? How to add overlay ???
        Toast.makeText(getApplicationContext(),"In onPause",Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
        Toast.makeText(getApplicationContext(),"In onResume",Toast.LENGTH_SHORT).show();

        this.removeContentView(); //??? How to remove overlay ???
    }
}

Are there any other ways to make it work on all Android version?


Viewing all articles
Browse latest Browse all 29593

Trending Articles