set Flag Secure - Android User Interface

Android examples for User Interface:Window

Description

set Flag Secure

Demo Code

/* ActivityHelper.java//  w w  w  .  jav a 2 s. c  o m
 * See the file "LICENSE.md" for the full license governing this code.
 */
//package com.java2s;
import android.annotation.TargetApi;

import android.app.Activity;

import android.os.Build;

import android.view.WindowManager;

public class Main {
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void setFlagSecure(Activity activity) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            // Prevent screenshots; FLAG_SECURE is restricted to HoneyComb and above to prevent issues with some Samsung handsets
            // Please see http://stackoverflow.com/questions/9822076/how-do-i-prevent-android-taking-a-screenshot-when-my-app-goes-to-the-background
            activity.getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_SECURE);
        }
    }
}

Related Tutorials