Android Question Manifest targeting Android 14

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello All,
I get the following error, while installing in Android 14 with SdkVersion = 34

Log Error:
java.lang.RuntimeException: Unable to start service xevolution.vrcg.v2900.demo.comms@6afd28c with Intent { cmp=xevolution.vrcg.v2900.demo/.comms }: java.lang.RuntimeException: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{2b7e237 15445:xevolution.vrcg.v2900.demo/u0a740} targetSDK=34

I have read that we now have to declare the foregroundServiceType.
I read the google notes, but I confess that I am a bit lost here.
For instance, in my Manifest shown below, I need to add that in all of the AddPermission("android.permission.... declarations?
Only in the AddManifestText(<uses-permission ... ?

Manifest Text:
'This code will be applied to the manifest file during compilation.

AddManifestText(<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="34"/> <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:largeHeap,"true")
SetApplicationAttribute(android:usesCleartextTraffic, "true")

AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="34" />)
AddManifestText(<uses-permission android:name="android.permission.INTERNET" />)

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

AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.INSTALL_PACKAGES)
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)

CreateResource(xml, provider_paths, <external-path name="root" path="" />)

AddManifestText(<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />)
AddManifestText(<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />)

'************ Google Play Services Base ************
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************
AddApplicationText(<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode,,face" />)

AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.CHANGE_WIFI_STATE)
AddPermission(android.permission.SCHEDULE_EXACT_ALARM)
AddPermission(android.permission.BLUETOOTH_ADVERTISE)
AddPermission(android.permission.BLUETOOTH_CONNECT)
AddPermission(android.permission.BLUETOOTH_SCAN)
AddPermission(android.permission.INTERNET)

AddApplicationText(<uses-library android:name="org.apache.http.legacy" android:required="false" />)
AddApplicationText(<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyD80wHumtgPImuxF_7Zk_aluqxAYsrtCOo"/>)
AddManifestText(<queries> <package android:name="com.google.android.apps.maps" /> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/pdf" /> </intent> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/vnd.ms-excel" /> </intent> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/msword" /> </intent> </queries>)

Can someone give me an example of the correct way to do it, please.

Thanks in advance
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
All your suggestions worked and now the App runs in Android 14 with no problems, except for an annoying message when opening the App, when first ran after install, stating that the App is not compatible with the latest android version. In other execution all is ok. Any idea why this message?
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
There shouldn't be any message with targetSdkVersion 33. Maybe you set it to a different value?

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

I am using platform 34 in the jar definition, by the way : C:\Android\platforms\android-34\android.jar

My manifest, as it is:


Manifest Text:
AddManifestText(<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="33"/> <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:largeHeap,"true")
SetApplicationAttribute(android:usesCleartextTraffic, "true")

AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="33" />)

AddManifestText(<uses-permission android:name="android.permission.INTERNET" />)

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

AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.INSTALL_PACKAGES)
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)

CreateResource(xml, provider_paths, <external-path name="root" path="" />)

AddManifestText(<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />)
AddManifestText(<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />)


'************ Google Play Services Base ************
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************
AddApplicationText(<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode,,face" />)

AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
'AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.CHANGE_WIFI_STATE)
AddPermission(android.permission.BLUETOOTH_ADVERTISE)
AddPermission(android.permission.BLUETOOTH_CONNECT)
AddPermission(android.permission.BLUETOOTH_SCAN)
AddPermission(android.permission.INTERNET)

AddPermission(android.permission.FOREGROUND_SERVICE_DATA_SYNC)
AddPermission(android.permission.USE_EXACT_ALARM)
AddPermission(android.permission.SCHEDULE_EXACT_ALARM)
AddPermission(android.permission.FOREGROUND_SERVICE_LOCATION)
AddPermission(android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING)

AddApplicationText(<uses-library android:name="org.apache.http.legacy" android:required="false" />)
AddApplicationText(<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyD80wHumtgPImuxF_7Zk_aluqxAYsrtCOo"/>)
AddManifestText(<queries> <package android:name="com.google.android.apps.maps" /> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/pdf" /> </intent> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/vnd.ms-excel" /> </intent> </queries>)
AddManifestText(<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:mimeType="application/msword" /> </intent> </queries>)

SetServiceAttribute(Comms, android:foregroundServiceType, "dataSync")
SetServiceAttribute(LocationService, android:foregroundServiceType, "location")
SetServiceAttribute(SyncDataService, android:foregroundServiceType, "dataSync")
SetServiceAttribute(SyncDataReCheckService, android:foregroundServiceType, "dataSync")
SetServiceAttribute(AlertService, android:foregroundServiceType, "remoteMessaging")
SetServiceAttribute(CheckRequestsChanges, android:foregroundServiceType, "dataSync")
SetServiceAttribute(CheckRequests, android:foregroundServiceType, "dataSync")
SetServiceAttribute(SyncStatusCheck, android:foregroundServiceType, "dataSync")
SetServiceAttribute(BackgroundUpdateService, android:foregroundServiceType, "dataSync")
SetServiceAttribute(notifications, android:foregroundServiceType, "remoteMessaging")
SetServiceAttribute(CheckDTUpdates, android:foregroundServiceType, "dataSync")
SetServiceAttribute(GetUpdateFilesService, android:foregroundServiceType, "dataSync")
 
Last edited:
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Well, it does. But only in the first execution thar runs after the first install. All further executions are message free.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…