I am starting a service by calling from activity
Android version is 12. GALAXY M31
when i compile in release mode, i get the following error
Logger connected to: samsung SM-M315F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
neworders_service_start (java line: 214)
java.lang.IllegalArgumentException: dynoapis.com: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:949)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:926)
at dynoapis.com.neworders._service_start(neworders.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at dynoapis.com.neworders.handleStart(neworders.java:103)
at dynoapis.com.neworders.access$000(neworders.java:8)
at dynoapis.com.neworders$1.run(neworders.java:71)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at dynoapis.com.neworders.onStartCommand(neworders.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
at android.app.ActivityThread.access$2100(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
neworders_service_start (java line: 214)
java.lang.IllegalArgumentException: dynoapis.com: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:949)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:926)
at dynoapis.com.neworders._service_start(neworders.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at dynoapis.com.neworders.handleStart(neworders.java:103)
at dynoapis.com.neworders.access$000(neworders.java:8)
at dynoapis.com.neworders$1.run(neworders.java:71)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at dynoapis.com.neworders.onStartCommand(neworders.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
at android.app.ActivityThread.access$2100(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
** Service (neworders) Destroy **
if i compile in debug mode i get
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
Error occurred on line: 0 (neworders)
java.lang.Exception: Sub service_start signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject dynoapis.com.neworders_subs_0._service_start() throws java.lang.Exception
class anywheresoftware.b4a.pc.RemoteObject,
service module code
B4X:
If FirstTime Then
StartService(neworders) if i comment this line, the app compiles and runs. But the service is not started.
End If
in manifest
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="31"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
)
'End of default text.
SetActivityAttribute(Main, android:keepScreenOn, "true")
SetActivityAttribute(Main, android:exported, "true")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
CreateResource(values, theme.xml,
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
<item name="android:colorPrimary">#FF000000</item>
<item name="android:colorPrimaryDark">#FF000000</item>
<item name="android:colorAccent">#FF000000</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
</resources>
)
CreateResourceFromFile(Macro, Core.NetworkClearText)
'----
SetApplicationAttribute(android:icon, "@drawable/icon")
'--------------------------------------
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="application/txt" />
<data android:mimeType="application/pdf" />
<data android:mimeType="application/msword" />
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
<data android:mimeType="application/vnd.ms-excel" />
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
</intent-filter>)
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
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,
<files-path name="name" path="shared" />
)
Android version is 12. GALAXY M31
when i compile in release mode, i get the following error
Logger connected to: samsung SM-M315F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
neworders_service_start (java line: 214)
java.lang.IllegalArgumentException: dynoapis.com: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:949)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:926)
at dynoapis.com.neworders._service_start(neworders.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at dynoapis.com.neworders.handleStart(neworders.java:103)
at dynoapis.com.neworders.access$000(neworders.java:8)
at dynoapis.com.neworders$1.run(neworders.java:71)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at dynoapis.com.neworders.onStartCommand(neworders.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
at android.app.ActivityThread.access$2100(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
neworders_service_start (java line: 214)
java.lang.IllegalArgumentException: dynoapis.com: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
at anywheresoftware.b4a.keywords.Common.createPendingIntentForAlarmManager(Common.java:949)
at anywheresoftware.b4a.keywords.Common.StartServiceAt(Common.java:926)
at dynoapis.com.neworders._service_start(neworders.java:214)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at dynoapis.com.neworders.handleStart(neworders.java:103)
at dynoapis.com.neworders.access$000(neworders.java:8)
at dynoapis.com.neworders$1.run(neworders.java:71)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at dynoapis.com.neworders.onStartCommand(neworders.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5092)
at android.app.ActivityThread.access$2100(ActivityThread.java:310)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
** Service (neworders) Destroy **
if i compile in debug mode i get
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
In activity
** Activity (main) Resume **
*** Service (neworders) Create ***
** Service (neworders) Start **
Error occurred on line: 0 (neworders)
java.lang.Exception: Sub service_start signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject dynoapis.com.neworders_subs_0._service_start() throws java.lang.Exception
class anywheresoftware.b4a.pc.RemoteObject,
service module code
B4X:
#Region Service Attributes
#StartAtBoot: false
#End Region
Sub Service_Destroy
End Sub
Sub Process_Globals
Dim Counter As Int
Dim nid As Int=1
Counter=0
Dim LastUpdateTime As Long
Dim nnew As Int=0
End Sub
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
End Sub
Sub Service_Start
Counter=Counter+1 ' This counting will not work for long. If it is important it should be saved in a file instead of a variable.
StartServiceAt("", DateTime.Now + 10 * DateTime.TicksPerSecond, True) 'schedule the next task to run in 30 seconds.
'''... do the required work
Log("neworders " & nnew)
If DateTime.Now > LastUpdateTime + 10 * DateTime.TicksPerSecond Then
nnew=CheckNewOrders
If nnew>0 Then
Service.StartForeground(nid, CreateNotification(" "))
Dim n As Notification = CreateNotification("New Orders ")
' if nid >1 then
n.Notify(nid)
nid=nid+1
End If
LastUpdateTime = DateTime.Now
End If
End Sub
Sub CreateNotification (Body As String) As Notification
''' If nnew=0 Then Return
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.AutoCancel=True
notification.SetInfo("New Orders", Body, activity2)
Return notification
End Sub
private Sub CheckNewOrders() As Int
Dim Cursor As Cursor
DateTime.DateFormat="yyyy-MM-dd"
Dim cdt As String=DateTime.Date(DateTime.Now)
'Log(DateTime.Date(DateTime.Now))
DateTime.DateFormat="dd/MM/yyyy"
Cursor = Main.Sql.ExecQuery("SELECT * FROM orderhead where status=0 and dtim like '" & cdt & "%'")
Dim ncnt As Int=Cursor.RowCount
Return ncnt
End Sub