Android Question App stops at Service_Start

Henrique Ayres

New Member
Licensed User
Longtime User
Google Cloud Message runs perfectly in a test device Motorola running Android Kitkat version 4.4.4
but fails on another test device Samsung Galaxy J2 Prime running Android Marshmallow 6.00.

The Android version of the device has been correctly detected and using RuntimePermissions Library
checks user's permission or not.

B4X:
        ...
        rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
        ...

After user's permission YES, the code tries to register the device on Google Cloud Messaging

B4X:
Sub RegisterDevice ()
    
    Dim i As Intent
    Dim i2 As Intent
    Dim r As Reflector

     i.Initialize("com.google.android.c2dm.intent.REGISTER", "")

     i.PutExtra("sender", MainCadastro.SenderId)

 
    i2 = r.CreateObject("android.content.Intent")
    
    Dim pi As Object

    
    pi = r.RunStaticMethod("android.app.PendingIntent", "getBroadcast", _
        Array As Object(r.GetContext, 0, i2, 0), _
        Array As String("android.content.Context", "java.lang.int", "android.content.Intent", "java.lang.int"))

    'it runs fine until the line bellow ... 
    i.PutExtra("app", pi)

    'it fails on the line bellow
    StartService(i)
    
End Sub

App stops at this point :

B4X:
Sub Service_Start (StartingIntent As Intent)
    
    Select StartingIntent.Action
        Case "com.google.android.c2dm.intent.REGISTRATION"
            HandleRegistrationResult(StartingIntent)
        Case "com.google.android.c2dm.intent.RECEIVE"
            MessageArrived(StartingIntent)
    End Select

End Sub

Manifest Editor

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="24"/>

...

...
'C2DM Permissions
AddManifestText(<permission android:name="$PACKAGE$.permission.C2D_MESSAGE" android:protectionLevel="signature" />)
AddPermission($PACKAGE$.permission.C2D_MESSAGE)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
' Push Service Receiver Attribute
SetReceiverAttribute(PushService, android:permission, "com.google.android.c2dm.permission.SEND")
' Service Receiver Text
AddReceiverText(PushService,
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="$PACKAGE$" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="$PACKAGE$" />
</intent-filter>)
'End of C2DM Permissions

I using B4A 7.80 - SDK Path : C:\Program Files\Android\android-sdk\platforms\android-24\android.jar

How can I solve this problem?
 

Henrique Ayres

New Member
Licensed User
Longtime User
This is the log

Logger connected to: samsung SM-G532MT
--------- beginning of main
Copying updated assets files (7)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
--------- beginning of system
sending message to waiting queue (activity_permissionresult)
running waiting messages (1)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (maincadastro) Create, isFirst = true **
** Activity (maincadastro) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
*** Service (pushservice) Create ***
** Service (pushservice) Start **
java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.c2dm.intent.REGISTER (has extras) }
at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1308)
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1346)
at android.app.ContextImpl.startService(ContextImpl.java:1321)
at android.content.ContextWrapper.startService(ContextWrapper.java:606)
at anywheresoftware.b4a.keywords.Common$9.run(Common.java:868)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7406)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 
Upvote 0
Top