Android Question [B4A] ANDROID 7.0 DISABLED AVAILABLE PERMISSION IN PREVIOUS VERSIONS

Fabian Alberto Moriconi

Member
Licensed User
Longtime User
I developed an APP that works correctly on devices that have versions of ANDROID 6.0 or lower.

When installing them on devices with ANDROID 7.0, the the WIFI network total access permission is disabled, an indispensable function for the APP operation.

The APPs were developed in B4A 5.70, updated with B4A 7.80.

I updated the Paths:
  • C:\Program Files\Java\jdk1.8.0_162\bin\javac.exe
  • C:\ANDROID\platforms\android-27\android.jar
The manifest that I always used and worked until ANDROID 6.0 is:

AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"

android:anyDensity="true"/>)​
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")

Based on other forum queries, I incorporated some permissions:

AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.ACCESS_WIFI_STATE)

I did not get ANDROID 7.0 to assign the permissions, as it did in previous versions of the operating system.

With ANDROID 7.0, only the Storage permission is enabled, although I also need full access to the network and the WRITE_EXTERNAL_STORAGE.

Maybe someone had the same problem and solved it, please, can you tell me how you did it or give me a clue where to look?. Thank you very much !
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Fabian Alberto Moriconi

Member
Licensed User
Longtime User

Thanks for the reply !
I have allready read this thread, but I didn't find the solution.

The last version of the APP is published in Google Play several months ago, when insalled in Android 6 or less it gets all necessary permissions (SD Card and Complete Internet Access), in Android 7 only gets SD Card permission. When I try to add this permission manually it's denied and the OS sends the next message:
Allows the application to create network sockets and use custom network protocols. the browser and other applications provide the necessary means for sending data to the internet, so you do not need to use this permission for that.

My APP is connected to an ESP8266 module that works as a WIFI Access Point, it does not provide Internet access, it only allows the WIFI connection between the Tablet and the device that contains said module. It is essential to enable this permission for me.

From what I read in the threads my APP should work as it is, but Android 7.0 does not allow it.
 
Upvote 0

Fabian Alberto Moriconi

Member
Licensed User
Longtime User
As long as targetSdkVersion is lower than 23 then you don't need to handle the permissions at runtime. It is possible that you were accessing a feature that is no longer exposed.
You should post the relevant code and error message.

Thanks for the reply !
Please, see my previous reply to DonManfred. The problem is that Android does not grant full access permission to the network, the Tablet makes the WIFI connection to the ESP8266 module that works as an Access Point, but when it tries to send a data packet it does not succeed, executes the fraction of Catch code:

B4X:
Sub TxString (Cadena() As Byte, IniCad As Int, LargoCad As Int)

    
    If Sck.Connected Then
        Try
            OutputStr.WriteBytes(Cadena, IniCad, LargoCad)
'            Indica que se espera una respuesta            
            WaitRta = True
'            Inicia el timer por si no responde para rehabilitar controles           
            TimeOut = TimeOutWIFI
            TimerRespuesta.Enabled = True
        Catch
            SckIO.Close
            Sck.Close
            TimeTCP.Enabled = False
            Funciones.BeepErr
            ToastMessageShow("Se interrumpió la conexión.", True)
        End Try
    Else
        TimeTCP.Enabled = False
        SckIO.Close
        Sck.Close
        Funciones.BeepErr
        ToastMessageShow("No se pudo conectar.", True)
    End If


End Sub
 
Upvote 0

Fabian Alberto Moriconi

Member
Licensed User
Longtime User
Upvote 0

Fabian Alberto Moriconi

Member
Licensed User
Longtime User
I don't understand. Does it raise an error or not?

When installing my APP in Android 7.0 it no longer connected with my device, which uses an ESP8266 module in Access Point mode (without Internet access), but always worked with previous versions of Android.

In the search for the reason for not connecting I incorrectly interpreted that Android 7.0 did not enable the permissions of total access to the Internet, since in previous versions of Android that permission was shown in a list, and in version 7.0 only the Storage permission was shown.

Each time I tried to send a data packet using the TxString function detailed above (belonging to a Service module called TCP), the portion of Catch code that closed the connection was executed.

I added the function in the Catch:
B4X:
ToastMessageShow(LastException.Message, True)

Which returns the following message:

android.os.NetworkOnMainThreadException

Which took me to the next Thread:


Based on this Thread I was able to solve my connection problem by executing the following function in the Main:
B4X:
Sub DisableStrictMode
    Dim jo As JavaObject
    jo.InitializeStatic("android.os.Build.VERSION")
    If jo.GetField("SDK_INT") > 9 Then
        Dim policy As JavaObject
        policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
        policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
        Dim sm As JavaObject
        sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
    End If
End Sub

Anyway, I think I understand that this is not the best solution, and that this error occurs by calling network functions from the Main.

I am currently calling the network functions (belonging to a Service module) from the Main, for example, as follows:
B4X:
CallSubDelayed(TCP, "TxCmdS")

Please, Which would be the correct way to execute network functions that start from an event generated by the User from the Main window?

Thank you very much !
 
Upvote 0
Top