I used a Java code written by @JordiCP in order to activate special permissions required on SDK26 +, to have floating windows.
The code works perfectly. Now I would like to transfer this sub into a code form, but without succeeding.
Here I give an example, maybe someone expert in Java will tell me where I'm wrong
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private OverLay_Permission As JavaObject
End Sub
Public Sub SDK_Version As Int
Dim I As Int
Dim J As JavaObject
j.InitializeStatic("android.os.Build.VERSION")
I=j.GetField("SDK_INT")
Return I
End Sub
Public Sub GetPermission(MainActivity As Object) As Boolean
If SDK_Version>=23 Then
OverLay_Permission.InitializeContext
Dim gotPermission As Boolean = OverLay_Permission.RunMethod("getSpecialPermissionValue",Null)
Else
Dim gotPermission As Boolean = True
End If
Return gotPermission
End Sub
Public Sub RequestPermission(MainActivity As Object)
OverLay_Permission.InitializeContext
OverLay_Permission.RunMethod("requestSpecialPermissionIfNeeded", Null)
End Sub
#if JAVA
import android.content.Intent;
import android.provider.Settings;
import android.net.Uri;
import android.app.Application;
public static int OVERLAY_PERMISSION_REQ_CODE = 1234;
public void requestSpecialPermissionIfNeeded() {
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + BA.applicationContext.getPackageName() ));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
}
public boolean getSpecialPermissionValue(){
return(Settings.canDrawOverlays(this));
}
#End If
The code works perfectly. Now I would like to transfer this sub into a code form, but without succeeding.
Here I give an example, maybe someone expert in Java will tell me where I'm wrong