Android Question How to block/ban screen shots of app

Peter Simpson

Expert
Licensed User
Hello fellow brainy developers, here is a good question for you :)
I've noticed that I can't take screen shots of my online banking apps (Lloyds, TSB, Santander or Barclays), that's great :cool:. Obviously once I close the banking apps the screen shot feature start working again.

My question is a simple really lol. How can I add/integrate this block screen shot feature into an app. I don't actually want to do this in any one of my apps, I'm just eager to know as this will probably be handy in the future.

The top message appears in all my online banking apps while I try to take a screen shot...
Screenshot_2015-03-19-19-31-40.jpg
 

Peter Simpson

Expert
Licensed User
That's true @NJDude as long as you have another phone or camera handy. It's just a learning precess for me, I find it interesting that an app can actually do this, me being me I just want to know how this is can be done as I never though that it was even possible.

But then again, most things are possible...
 

DonManfred

Expert
Licensed User
You can try this. I cannot test cause i dont know how to take a screenshot on my Custom ROM :D

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim nativeMe As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("main")
    nativeMe.InitializeContext
    nativeMe.RunMethod("securescreen",Null)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If Java
import android.annotation.TargetApi;
import android.content.Context;
import android.view.WindowManager.*;
public void securescreen() {
    this.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
}

#End If
 

DonManfred

Expert
Licensed User
Here is the WORKING version.
It works on a 4.x device of peter but it works not on a device with android 5.1 of peter.
BUT it works ;)

Solution: I needed to hook into the onCreate

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim nativeMe As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("main")
    nativeMe.InitializeContext
    'nativeMe.RunMethod("securescreen",Null)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If Java
import android.annotation.TargetApi;
import android.content.Context;
import android.view.WindowManager.*;
public void _onCreate() {
    this.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
}
#End If
 

NJDude

Expert
Licensed User
The code works, but also it seems I've discovered a bug in B4A, if you just copy the Java code it also works, what I mean is, no need to add the JavaObject lib or nativeMe.InitializeContext, in other words, the code below will also run and work:
B4X:
Sub Process_Globals

End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)	
	
#If Java
import android.annotation.TargetApi;
import android.content.Context;
import android.view.WindowManager.*;
public void _onCreate() {
    this.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
}
#End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause(UserClosed As Boolean)

End Sub
 

Beja

Expert
Licensed User
@NJDude
I will call your discovery undocumented feature, rather than a bug.. I hope Erel doesn't fix this bug.. lol.
 

DonManfred

Expert
Licensed User
The code works, but also it seems I've discovered a bug in B4A, if you just copy the Java code it also works, what I mean is, no need to add the JavaObject lib or nativeMe.InitializeContext, in other words, the code below will also run and work:
i think it´s only needed if we want to call method of the inline java code..
 
Top