Android Tutorial Android push notification (C2DM) framework and tutorial

desbiens

Member
Licensed User
Longtime User
Error: INVALID_SENDER

After pressing the "Register" button, the demo application popup the following error:
Error: INVALID_SENDER

What this mean and how to fix this problem?
 

desbiens

Member
Licensed User
Longtime User
Yes the SenderID is setup properly.

This is my code:
'Activity module
Sub Process_Globals
Dim Package, DeviceBoardPassword, BoardUrl, SenderId, DeviceName As String
DeviceBoardPassword = "34f34fkj02dz"
BoardUrl = "http://b4aserver.basic4ppc.com/c2dm_board.php"
'both these fields should be set to match your application package and SenderId.
Package = "t24.database_test"
SenderId = "[email protected]"
End Sub

Sub Globals
Dim btnRegister As Button
Dim txtName As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnRegister_Click
If Regex.IsMatch("[\d\w]+", txtName.Text) = False Then
ToastMessageShow("Name not valid", True)
Return
End If
Register(txtName.Text)
End Sub

Sub Register(Name As String)
Dim r As Reflector
Dim i As Intent
i.Initialize("", "")
i.SetComponent(Package & "/.pushservice")
i.PutExtra("MyRequest", "Register")
DeviceName = Name
StartService(i)
End Sub

Sub Unregister(Name As String)
Dim i As Intent
i.Initialize("", "")
i.SetComponent(Package & "/.pushservice")
i.PutExtra("MyRequest", "Unregister")
DeviceName = Name
StartService(i)
End Sub

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: Manifest Editor
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<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.
'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>)
 

choliz

Member
Licensed User
Longtime User
Erel,

To begin with: what an amazing job have you done with this solution! I had 10 years since the last time that I developed using VB and always wanted to jump in to the mobile wagon. WIth your software I can do anything really fast.

One thing that I need for my flagship app is the Notification service, but when I went to the google developer's page to sign up to C2DM on 06/27, I found this:

Important: C2DM has been officially deprecated as of June 26, 2012. At that time C2DM stopped accepting new users and quota requests. C2DM has been replaced by Google Cloud Messaging for Android (GCM). The C2DM service will continue to be maintained in the short term, but developers must use GCM for new development. We also encourage developers to move existing C2DM applications to GCM to take advantage of GCM features. See the C2DM-to-GCM Migration document for more information.

Are you planning to post a tutorial about GCM?

Thanks in advance
 

pjsmith

Member
Licensed User
Longtime User
That's excellent. I for one look forward to it. Thanks. I use c2dm, but the change was news to me.
 

cbal03

Member
Licensed User
Longtime User
Valuable information! Thank you so much!
 

desbiens

Member
Licensed User
Longtime User
Is there a way that I could edit my code so that I do not receive push messages when the app is turned off? Or is this done within the manifest file?
 

dibesw

Active Member
Licensed User
Longtime User
When I push button Register, nothing happens (no message return). Why?
I have register in Google Developers (1 our ago)
Package and SenderId are correct

B4X:
Sub Process_Globals
    Dim Package, DeviceBoardPassword, BoardUrl, SenderId, DeviceName As String
    DeviceBoardPassword = "34f34fkj02d3"
    BoardUrl = "http://b4aserver.basic4ppc.com/c2dm_board.php"

   
    'both these fields should be set to match your application package and SenderId.   
    Package = "progetto-tecnomobileclienti58"
    SenderId = "[email protected]"
End Sub

I have also modified Manifest editor

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" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'
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>)
 

ramontst

New Member
Licensed User
Longtime User
Hello,

When i tried to send a message, i got this result :

B4X:
java.lang.RuntimeException: java.io.IOException: Server returned HTTP response
code: 401 for URL: https://android.apis.google.com/c2dm/send
        at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:66)
        at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:63)
        at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:228)

this is a ClientLogin Auth token problem but i don't understand what i must do.

Do you know ?
I have
Make sure that you entered the correct values in config.txt. Were you able to register the device successfully?
There should be a file named oauth.txt in the folder of the desktop tool. Delete it and see if it is recreated.

I have exactly the same problem. I verify the config.txt values, when I registered the device successfully and I deleted the oauth.txt file and when I re-started the app this file was created again. But I continue receiving the same error.
 

DonManfred

Expert
Licensed User
Longtime User
I have exactly the same problem. I verify the config.txt values, when I registered the device successfully and I deleted the oauth.txt file and when I re-started the app this file was created again. But I continue receiving the same error.

See Post #133 (the one in top of your post...

 
Top