how to disable screenshot in android programmatically
Hi in this android article we discuss how to disable screenshots in our android programmatically. Like if you want to user can’t take screenshots of your application so we disable screen capture in android using Kotlin. So how to disable screenshots programmatically user can’t take screenshots in our app. This is helpful for security issues today so many App disables these screenshots not allow. We increase our app security for data purposes and some of the features.
disable screenshot security android
So Let’s follow these steps to implementation of if your want I implement in the old project open your project and make MyApplication Kotlin file and follow these code.
if you want to disable the full App screenshot android programmatically use MyApplication Class and in if your want a single screen you can use these on activity.
Full App Screenshots disable.
class MyApplication : MultiDexApplication() { /* public static Retrofit getLocalClient(String BaseUrl) { if (localRetrofit == null) { localRetrofit = new Retrofit.Builder() .baseUrl(BaseUrl) .addConverterFactory(GsonConverterFactory.create()) .build(); } return localRetrofit; } */ //Instance of Retrofit library for creating OTP client. //Selected loan storage var selectedUserLoan = UserLoans() // private DaoSession daoSession; // private FirebaseAnalytics mFirebaseAnalytics;//Firebase analytics instance private val locale: Locale? = null /* public FirebaseAnalytics getmFirebaseAnalytics() { return mFirebaseAnalytics; } public void setmFirebaseAnalytics(FirebaseAnalytics mFirebaseAnalytics) { this.mFirebaseAnalytics = mFirebaseAnalytics; }*/ override fun onCreate() { super.onCreate() setupActivityListener() }
private fun setupActivityListener() { registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks { override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE) } override fun onActivityStarted(activity: Activity) {} override fun onActivityResumed(activity: Activity) {} override fun onActivityPaused(activity: Activity) {} override fun onActivityStopped(activity: Activity) {} override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} override fun onActivityDestroyed(activity: Activity) {} }) }
if you want to disable a single screen follow this code.
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
setContentView()
method.