Android Question [Solved]Block/Permit ScreenShot using B4XPage

Theera

Expert
Licensed User
Longtime User
Refer to this I 've test the code about Block/Permit ScreenShot using B4XPage
My error is belows

my Code is belows

B4X:
Private Sub B4XUISwitch1_Click
    If B4XUISwitch1.SwitchState Then
        Log(B4XUISwitch1.SwitchState)
        'Allow screenshots
        Dim wrk_jo As JavaObject=Me  'using B4XPage
        'wrk_jo.InitializeContext
        wrk_jo.RunMethod("unsecurescreen", Null)

    Else
        
        'Block screenshots
        Dim wrk_jo As JavaObject=Me 'using B4XPage
        'wrk_jo.InitializeContext
        wrk_jo.RunMethod("securescreen", Null)

            
    End If
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);  
}  
public void unsecurescreen() {  
    this.getWindow().clearFlags(LayoutParams.FLAG_SECURE);  
}  
#End If
 
Solution
B4X:
Private Sub SetSecureScreenState (Secure As Boolean)
    Dim jme As JavaObject = Me
    jme.RunMethod(IIf(Secure, "securescreen", "unsecurescreen"), Null)
End Sub


  
#If Java  
import android.annotation.TargetApi;  
import android.content.Context;  
import android.view.WindowManager.*;  
public void securescreen() {  
    getBA().activity.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);  
}  
public void unsecurescreen() {  
    getBA().activity.getWindow().clearFlags(LayoutParams.FLAG_SECURE);  
}  
#End If

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Private Sub SetSecureScreenState (Secure As Boolean)
    Dim jme As JavaObject = Me
    jme.RunMethod(IIf(Secure, "securescreen", "unsecurescreen"), Null)
End Sub


  
#If Java  
import android.annotation.TargetApi;  
import android.content.Context;  
import android.view.WindowManager.*;  
public void securescreen() {  
    getBA().activity.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);  
}  
public void unsecurescreen() {  
    getBA().activity.getWindow().clearFlags(LayoutParams.FLAG_SECURE);  
}  
#End If
 
Upvote 1
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…