Java Question [SOLVED] Problem with Java

Star-Dust

Expert
Licensed User
Longtime User
I used a Java code written by @JordiCP in order to activate special permissions required on SDK26 +, to have floating windows.

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
 

Attachments

  • sample.zip
    6.9 KB · Views: 335

Star-Dust

Expert
Licensed User
Longtime User
this
B4A Versione: 7.80
Analisi del Codice. (0.01s)
Compilazione del codice. (3.48s)

File ObsucastorMap.txt creato nella cartella Objects.
Compilazione del codice di layouts (0.17s)
Organizzazione Librerie. (0.08s)
Generazione file R. (10.51s)
Compilazione del codice Java prodotto. Error
B4A line: 15
End Sub
javac 1.8.0_151
src\b4a\example\code.java:80: error: cannot find symbol
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
^
symbol: method startActivityForResult(Intent,int)
location: class code
if the Java lines are moved to the activity main, it works correctly
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Star-Dust

Expert
Licensed User
Longtime User
Ok thanks @Erel I'll try
 
Top