Android Question GCM registration problem

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I get

** Service (pushservice) Start **
java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER (has extras) } without permission com.google.android.c2dm.permission.RECEIVE

This is my code, taken from the example https://www.b4x.com/android/forum/t...otification-gcm-framework-and-tutorial.19226/



B4X:
Sub RegisterDevice (Unregister As Boolean)
   Dim i As Intent
   If Unregister Then     
     i.Initialize("com.google.android.c2dm.intent.UNREGISTER", "")
   Else
     i.Initialize("com.google.android.c2dm.intent.REGISTER", "")
     Log (Main.senderid)
     ' the senderid is valid
     i.PutExtra("sender", Main.SenderId)
   End If
   Dim r As Reflector
   Dim i2 As Intent
   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"))
   i.PutExtra("app", pi)
   Log ("startservice")
   StartService(i)
   Log ("started")
   ' the program comes here
End Sub

Sub HandleRegistrationResult(Intent As Intent)
    ' this point is never reached
   If Intent.HasExtra("error") Then
     Log("Error: " & Intent.GetExtra("error"))
     ToastMessageShow("Error: " & Intent.GetExtra("error"), True)
   Else If Intent.HasExtra("unregistered") Then
     If hcInit = False Then hc.Initialize("hc")
     Dim req As HttpRequest
     ' xxx
     ' req.InitializeGet(Main.BoardUrl & "?device_password=" & Main.DeviceBoardPassword & _
     '    "&name=" & Main.DeviceName & "&id=") 'Empty id is sent here. This will cause the board to delete this name.
     ' hc.Execute(req, UnregisterTask)
   Else If Intent.HasExtra("registration_id") Then
     If hcInit = False Then hc.Initialize("hc")
     Dim rid As String
     rid = Intent.GetExtra("registration_id")
     Dim req As HttpRequest
'     req.InitializeGet(Main.BoardUrl & "?device_password=" & Main.DeviceBoardPassword & _
'       "&name=" & Main.DeviceName & "&id=" & rid)
'     hc.Execute(req, RegisterTask)
   End If
End Sub

What am I doing wrong? I changed nothing but the sender-ID, which I got from Google.
 

DonManfred

Expert
Licensed User
Longtime User
It sems that you are missing the permission com.google.android.c2dm.permission.RECEIVE

Try to add
B4X:
AddPermission(com.google.android.c2dm.permission.RECEIVE)
to your manifest code
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Thank you! Now I copied the whole text from the instructions to the manifest editor and get "An error occured while parsing the packet.

This is my manifest code:

B4X:
'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: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
  android:normalScreens="true"
  android:smallScreens="true"
  android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddPermission(android.permission.READ_PHONE_STATE)
SetActivityAttribute(Main,android:theme,"@style/CustomActionBarTheme")
SetActivityAttribute(Draw,android:theme,"@style/CustomActionBarTheme")
SetActivityAttribute(Kamera,android:theme,"@style/CustomActionBarTheme")
SetActivityAttribute(Galerie,android:theme,"@style/CustomActionBarTheme")
SetActivityAttribute(Upload,android:theme,"@style/CustomActionBarTheme")
SetActivityAttribute(Settings,android:theme,"@style/CustomActionBarTheme")
SetApplicationAttribute(android:largeHeap,"true")

'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>)
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
When I re3move this line

AddManifestText(<permission android:name="$PACKAGE$.permission.C2D_MESSAGE" android:protectionLevel="signature" />)

the program compiles and runs, the method RegisterDevice is called, but neither HandleRegistrationResult nor hc_ResponseSuccess nor hc_ResponseError.

With this line in the Manifest text, I get Parsing error (in German: Beim Parsen des Pakets ist ein Problem aufgetreten)

:(
 
Last edited:
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
There is no error message, this screen appears on the phone
 

Attachments

  • Screenshot_2015-09-06-12-32-53.png
    Screenshot_2015-09-06-12-32-53.png
    47.6 KB · Views: 234
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Out of curiosity, @Erel

Have an android Packagename the need to get written alsways LOWERCASE???

The old Packagename was "FB.Tag" and this causs the malformed manifest error while installing the app i guess...

I changed it to fb.tag.example just to test... Program were installed correctly after the change
 
Upvote 0
Top