Android Question My application can't connect to the internet

luthfiagata

Member
I’ve already tried following the steps provided, and it was successfully installed on my device (Android 14). However, I’m facing another issue: my application cannot connect to the database I’ve set up. This problem keeps happening repeatedly, and even with the help of ChatGPT, I still haven’t found a solution.

this is my
manifest code:
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:usesCleartextTraffic, "true")
SetApplicationAttribute(android:networkSecurityConfig, "@xml/network_security_config")

AddManifestText(<uses-sdk   android:minSdkVersion="13" android:compileSdkVersion="33" android:targetSdkVersion="34"/>)
AddManifestText(<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>)

' Permissions for Android 13+
AddManifestText(<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />)
AddManifestText(<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />)
AddManifestText(<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />)

' For Android 12 and below
AddPermission("android.permission.READ_EXTERNAL_STORAGE")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")

AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)

' Other necessary permissions
AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission("android.permission.ACCESS_COARSE_UPDATES")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")

CreateResourceFromFile(Macro, Themes.LightTheme)


Main Code:
#Region  Project Attributes
    #ApplicationLabel: E-Karyawan
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
    #AdditionalRes: ..\Files
    #AdditionalRes: ..\Objects\res, android.res

#End Region

connection code:
    'Code module
    'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
    Dim mh As MysqlHandler
    Dim rs As ResultSet
    Dim result As Int
End Sub

Sub koneksi
    mh.Initialize("myserver","mydatabase","username","password")
    Log("Coba koneksi ke database...")
    
    If mh.isConnected = False Then
        Log("Koneksi gagal!")
        result = Msgbox2("Oops, ada masalah dalam jaringan", "ERROR", "RELOAD", "", "Exit", LoadBitmap(File.DirAssets, "koneksi_error.png"))
        
        If result = DialogResponse.POSITIVE Then
            MsgboxAsync("Aplikasi ini memerlukan akses internet, nyalakan data atau hubungkan keWIFI", "WARNING")
        Else If result = DialogResponse.NEGATIVE Then
            MsgboxAsync("Aplikasi ini memerlukan akses internet, nyalakan data atau hubungkan keWIFI", "WARNING")
        End If
        
        ExitApplication
    Else
        Log("Koneksi berhasil!")
    End If
End Sub

'koneksi setelah instal gagal koneksi

I’ve already tried creating the
network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">{mydomain}</domain>
    <!--    <domain>192.168.1.10</domain>      Jika pakai IP -->
    </domain-config>
</network-security-config>
file and followed the steps provided by ChatGPT, but it still didn’t work.
 

Attachments

  • WhatsApp Image 2025-04-12 at 10.40.05_54198591.jpg
    WhatsApp Image 2025-04-12 at 10.40.05_54198591.jpg
    51.1 KB · Views: 87

aeric

Expert
Licensed User
Longtime User
I think your question is to connect your B4A app to your remote MySQL database instead of connecting to the Internet.

There are other options besides the solutions suggested by Erel above.
  1. Create Web service using PHP, ASP.NET or other backend language
  2. Create Web API server
  3. Use jRDC2
 
Upvote 0
Top