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
B4A Version: 13.40
Parsing code. (0.33s)
Java Version: 19
Building folders structure. (0.17s)
Running custom action. (0.22s)
Compiling code. (0.50s)
Compiling layouts code. (0.08s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Compiling resources (0.20s)
Linking resources (0.89s)
build tools: 36.0.0, android jar: android-36
Compiling generated Java code. Error
B4A line: 73
End Sub
src\b4a\example\b4xmainpage.java:114: error: cannot find symbol
this.getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
^
symbol: method getWindow()
1 error
only showing the first 1 errors, of 2 total; use -Xmaxerrs if you would like to see more

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

DonManfred

Expert
Licensed User
Longtime User
The Thread is from 2021 and probably made for Activities projects.
You need to adapt it to b4xpages.

I can´t help you here sorry
 
Last edited:
Upvote 0

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
Top