Android Tutorial Android push notification (C2DM) framework and tutorial

hackhack

Active Member
Licensed User
Longtime User
Background

Google provides a service named Android Cloud to Device Messaging Framework (C2DM) which allows developers to send data to their applications running on Android devices. Unlike most solutions which involve polling some server, this service is a "push" service (similar to SMS messages).

Although It may not be related to this, I'd love to be able to understand how it can be a "push" - how would an Android device magically know there is something? Surely it must check at intervals to see if there is something.
 

petri2000

Member
Licensed User
Longtime User
C2DM sign up delay.

C2DM, this seems exactly what we need for our app. I have signed up about 8 days ago with 1 account and 3 days ago with another one to get access to the services, I guess it was a google automated email that said "you will have access within the next day or so". Do, anybody know how to speed up the process? Are there any specific criterias that I would met for getting an account? I know it has nothing to do with B4A business, but I am looking for clues if there is someone with some info to get an account. As this is something we would really need! I have been trying to find answers else where... But nothing, this is my last resort.....

Cheers,
Petri

PS. Yes, I am looking into xtify as well but would prefeer google DS.
 

myriaddev

Active Member
Licensed User
Longtime User
SUCCESS: xxxxxxxx

WOW! It worked (my first server app)! What does "success: xxxxx"
mean ? That the message arrived at the Device ? That the message
was sent only ? That the message was read ? What does the number
mean ?
Thank you Erel,
Jerry
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

talalilo

New Member
code sample

@myriaddev
Kindly give me your example to test with, as every time i got 401 unauthorized error
 

jnbarban

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 ?
 

mitobobo

Member
Licensed User
Longtime User
Hello,

I'm sorry in advance for my English:sign0013:

I modified the Package = "" and SenderId = "" in the client code, and replaced all the occurrences of anywheresoftware.b4a.samples.push with my package name(com.sl.comando) in the Manifest. Then I uploaded the app to my device(HTC Desire), but it crashs while opening: "Unexpected Push Example application termination (process com.sl.comando). Try again". Any idea why I get that?

Thank you very much in advance for your help.
 

mitobobo

Member
Licensed User
Longtime User
Oh, I get this:

B4X:
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.sl.comando cmp=com.sl.comando/.main } from pid 12842
Start proc com.sl.comando for activity com.sl.comando/.main: pid=12958 uid=10072 gids={3003}
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x40240560)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sl.comando/com.sl.comando.main}: java.lang.ClassNotFoundException: com.sl.comando.main in loader dalvik.system.PathClassLoader[/data/app/com.sl.comando-1.apk]
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
   at android.app.ActivityThread.access$1500(ActivityThread.java:123)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:130)
   at android.app.ActivityThread.main(ActivityThread.java:3835)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.sl.comando.main in loader dalvik.system.PathClassLoader[/data/app/com.sl.comando-1.apk]
   at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
   at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
   ... 11 more
  Force finishing activity com.sl.comando/.main
Activity pause timeout for HistoryRecord{40c7a158 com.sl.comando/.main}
** Activity (main) Resume **

Thank you very much again
 

mitobobo

Member
Licensed User
Longtime User
B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sl.comando"
      android:versionCode="1"
      android:versionName=""
     android:installLocation="internalOnly">
      <uses-sdk android:minSdkVersion="4" />
      <supports-screens
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true"
          android:anyDensity="true"/>
    <application android:icon="@drawable/icon" android:label="Push Example">
       
        <activity android:windowSoftInputMode="stateHidden" android:launchMode="singleTop" android:name=".main"
                  android:label="Push Example" android:screenOrientation="unspecified">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="pushservice"></service>
      <receiver android:name="pushservice$pushservice_BR" android:permission="com.google.android.c2dm.permission.SEND">
       <intent-filter>
              <action android:name="com.google.android.c2dm.intent.RECEIVE" />
              <category android:name="com.sl.comando" />
          </intent-filter>
          <!-- Receive the registration id -->
          <intent-filter>
              <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
              <category android:name="com.sl.comando" />
          </intent-filter>

      </receiver>

    </application>
   <uses-permission android:name="android.permission.INTERNET"/>
   <permission android:name="com.sl.comando.permission.C2D_MESSAGE" android:protectionLevel="signature" />
   <uses-permission android:name="com.sl.comando.permission.C2D_MESSAGE" />
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


</manifest>

Thank you very much.
 

pinoy_ako

Member
Licensed User
Longtime User
why when i compile the device sample, i got this error:
Compiling code. Error
Error parsing program.
Error description: Unknown type: reflector
Are you missing a library reference?
Occurred on line: 52
Dim r As Reflector
 
Top