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.
After user's permission YES, the code tries to register the device on Google Cloud Messaging
App stops at this point :
Manifest Editor
I using B4A 7.80 - SDK Path : C:\Program Files\Android\android-sdk\platforms\android-24\android.jar
How can I solve this problem?
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?