Android Question How to block/ban screen shots of app

Discussion in 'Android Questions' started by Peter Simpson, Mar 20, 2015.

  1. Peter Simpson

    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
     
  2. NJDude

    NJDude Expert Licensed User

    That's nice, but a little bit useless too, I mean, you cannot take a screenshot but you can take a picture of the device. ;)
     
    Cableguy, KZero and Peter Simpson like this.
  3. Peter Simpson

    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...
     
  4. DonManfred

    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

    Code:
    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
     
    Erel, RandomCoder and KMatle like this.
  5. DonManfred

    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

    Code:
    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
     
  6. NJDude

    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:
    Code:
    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
     
  7. Beja

    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.
     
  8. DonManfred

    DonManfred Expert Licensed User

    i think it´s only needed if we want to call method of the inline java code..
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    It is not a bug. Hooks have nothing to do with JavaObject. This specific hook is called before any other code is executed.
     
    NJDude and thedesolatesoul like this.
  10. Peter Simpson

    Peter Simpson Expert Licensed User

    Last edited: Mar 23, 2015
    DonManfred likes this.
  11. DonManfred

    DonManfred Expert Licensed User

    Last last? ;-)
     
    Peter Simpson likes this.
  12. NJDude

    NJDude Expert Licensed User

    I understand, but still, why this code should execute as is anyway?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice