rfresh Well-Known Member Licensed User Longtime User May 18, 2012 #1 OK, I finally got the C2DM system working on my Droid2 phone. At this point I am only using Erel's C2DM sample coding. Mainly the device code and the command line batch file to send the msg. I have two questions. (1) In the Sub below, what is the Regex function doing to the txtName.Text string? Code: 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 I want to make the registration of C2DM transparent (if possible) to my users. (2) What name can I use to programatically register their devices? In playing with the sample code Erel has kindly provided, I just chose 'droid2' because my phone is a Droid2. But clearly this won't work for many users with Droid2 phones as I need to message them one at a time and not as a group. Should I use the device ID string since this a unique string? Update: I tried to use the Device ID string to register my device but it didn't work and wouldn't register my Droid2. I got the msg: Code=403, invalid server password. So now I don't know what a correct registration string represents? Thanks...
OK, I finally got the C2DM system working on my Droid2 phone. At this point I am only using Erel's C2DM sample coding. Mainly the device code and the command line batch file to send the msg. I have two questions. (1) In the Sub below, what is the Regex function doing to the txtName.Text string? Code: 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 I want to make the registration of C2DM transparent (if possible) to my users. (2) What name can I use to programatically register their devices? In playing with the sample code Erel has kindly provided, I just chose 'droid2' because my phone is a Droid2. But clearly this won't work for many users with Droid2 phones as I need to message them one at a time and not as a group. Should I use the device ID string since this a unique string? Update: I tried to use the Device ID string to register my device but it didn't work and wouldn't register my Droid2. I got the msg: Code=403, invalid server password. So now I don't know what a correct registration string represents? Thanks...
Erel B4X founder Staff member Licensed User Longtime User May 18, 2012 #2 The regex is used to only allow alphanumeric characters. You probably need to escape other characters. You can use this code to generate a random id: Code: Sub FindRandomId As String If File.Exists(File.DirInternal, "id.txt") Then Return File.ReadString(File.DirInternal, "id.txt") Else Dim id As Int id = Rnd(0, 0x7fffffff) File.WriteString(File.DirInternal, "id.txt") Return id Return End Sub It is unlikely that two devices will get the same value (there is a higher chance that Phone.DeviceId will return the same value for two phones). Upvote 0
The regex is used to only allow alphanumeric characters. You probably need to escape other characters. You can use this code to generate a random id: Code: Sub FindRandomId As String If File.Exists(File.DirInternal, "id.txt") Then Return File.ReadString(File.DirInternal, "id.txt") Else Dim id As Int id = Rnd(0, 0x7fffffff) File.WriteString(File.DirInternal, "id.txt") Return id Return End Sub It is unlikely that two devices will get the same value (there is a higher chance that Phone.DeviceId will return the same value for two phones).
rfresh Well-Known Member Licensed User Longtime User May 18, 2012 #3 Thanks Erel. I was able to switch over to using my own database on my own server. And, at least I was able to successfully register my Droid2 phone. And I can see the record for this ID in my database. However, I can't send a message to it. Any idea's on what I can check? Code: C:\0C2DM\Desktop>b4a_c2dm.bat send 8200 "new test" C:\0C2DM\Desktop>java -cp b4a_c2dm.jar anywheresoftware.b4a.c2dm.C2DM send 8200 "new test" java.lang.RuntimeException: No id found for name: 8200 at anywheresoftware.b4a.c2dm.C2DM.getIdForName(C2DM.java:100) at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:51) at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:228) Do I need to change anything in the .bat file? java -cp b4a_c2dm.jar anywheresoftware.b4a.c2dm.C2DM %* Last edited: May 19, 2012 Upvote 0
Thanks Erel. I was able to switch over to using my own database on my own server. And, at least I was able to successfully register my Droid2 phone. And I can see the record for this ID in my database. However, I can't send a message to it. Any idea's on what I can check? Code: C:\0C2DM\Desktop>b4a_c2dm.bat send 8200 "new test" C:\0C2DM\Desktop>java -cp b4a_c2dm.jar anywheresoftware.b4a.c2dm.C2DM send 8200 "new test" java.lang.RuntimeException: No id found for name: 8200 at anywheresoftware.b4a.c2dm.C2DM.getIdForName(C2DM.java:100) at anywheresoftware.b4a.c2dm.C2DM.sendMessageTo(C2DM.java:51) at anywheresoftware.b4a.c2dm.C2DM.main(C2DM.java:228) Do I need to change anything in the .bat file? java -cp b4a_c2dm.jar anywheresoftware.b4a.c2dm.C2DM %*
Erel B4X founder Staff member Licensed User Longtime User May 20, 2012 #4 Do you see a device with the id 8200 in the database? Upvote 0
rfresh Well-Known Member Licensed User Longtime User May 20, 2012 #5 Yes, it is in my database. I created a new unique device id with the random generator code you gave me and registered it successfully. But I still can't send a msg to it. When I shift things back to using your server it works fine but when I try and use my server I can't send to my droid2 phone. The oauth.txt file data string matches the database record id field. See attachments... Last edited: May 20, 2012 Upvote 0
Yes, it is in my database. I created a new unique device id with the random generator code you gave me and registered it successfully. But I still can't send a msg to it. When I shift things back to using your server it works fine but when I try and use my server I can't send to my droid2 phone. The oauth.txt file data string matches the database record id field. See attachments...
Erel B4X founder Staff member Licensed User Longtime User May 20, 2012 #6 Have you configered the desktop tool to use your server instead of the default one? Upvote 0
rfresh Well-Known Member Licensed User Longtime User May 20, 2012 #7 Yes I configure the file config.txt for my server. I checked it and then saved it again. Now, for the first time, when I sent from the command line window, it returned success!! But I never saw the 'hello' msg display on my device. Maybe the msg is delayed? I have a droid3 phone too. When I send from the command line, won't I have to edit the oauth.txt file and put in the droid3 id string to make it work for that phone? Update: I was able to successfully send to my droid3 phone!! I will try my droid2 phone again. My goal is to send msgs from my php website to one phone at a time but have many customer phones to send to. So, I'm not clear yet on how the oauth.txt file would work in that environment? Last edited: May 20, 2012 Upvote 0
Yes I configure the file config.txt for my server. I checked it and then saved it again. Now, for the first time, when I sent from the command line window, it returned success!! But I never saw the 'hello' msg display on my device. Maybe the msg is delayed? I have a droid3 phone too. When I send from the command line, won't I have to edit the oauth.txt file and put in the droid3 id string to make it work for that phone? Update: I was able to successfully send to my droid3 phone!! I will try my droid2 phone again. My goal is to send msgs from my php website to one phone at a time but have many customer phones to send to. So, I'm not clear yet on how the oauth.txt file would work in that environment?
Erel B4X founder Staff member Licensed User Longtime User May 20, 2012 #8 You do not need to touch this file. The authentication token is for the gmail account not for a specific device. Upvote 0
You do not need to touch this file. The authentication token is for the gmail account not for a specific device.
rfresh Well-Known Member Licensed User Longtime User May 20, 2012 #9 Ahhhh I see. Ok, I got this working on all three of my devices (droid2, droid3 and a wifi tablet). Thanks for your patience and help Erel. Can you point me in the direction where I can read about sending these mgs from a php file on a Linux website? Upvote 0
Ahhhh I see. Ok, I got this working on all three of my devices (droid2, droid3 and a wifi tablet). Thanks for your patience and help Erel. Can you point me in the direction where I can read about sending these mgs from a php file on a Linux website?
Erel B4X founder Staff member Licensed User Longtime User May 21, 2012 #10 The sender app is a java application. Search for a PHP script that runs Java application. Upvote 0
rfresh Well-Known Member Licensed User Longtime User May 21, 2012 #11 I notice when I unregisted my device, it's record get deleted from my database but not when I uninstall my app. Do we have any way to remove known orphan records? Upvote 0
I notice when I unregisted my device, it's record get deleted from my database but not when I uninstall my app. Do we have any way to remove known orphan records?
rfresh Well-Known Member Licensed User Longtime User May 21, 2012 #12 Erel said: The sender app is a java application. Search for a PHP script that runs Java application. Click to expand... The following may be of interest of others who want to setup their own web server with Java so they can make use of C2DM. In my situation, I need to make PHP send the C2DM message to my device, so this means installing Java on my Linux server. My hosting company is Hostgator and they gave me these options for my VPS server: install for free Tom Cat Java 5.5 or for a 75.00 install fee, install Tom Cat Java vers 6 or 7. Here is the next surprise they tell me: My VPS server (and BTW way, they they can't run Java on a shared server because it is too resource hungry, only on VPS or dedicated servers) only has 800MB of ram and they recommend 2MB at a greatly increased monthly cost! I told them to install 5.5 and I'll see how the performance is on my server. If it turns out I don't have enough ram, I don't think I want to pay 50.00 per month more for enough server memory just to run Tom Cat Java. I'll just have to forget about trying to implement C2DM on a Linux server. Upvote 0
Erel said: The sender app is a java application. Search for a PHP script that runs Java application. Click to expand... The following may be of interest of others who want to setup their own web server with Java so they can make use of C2DM. In my situation, I need to make PHP send the C2DM message to my device, so this means installing Java on my Linux server. My hosting company is Hostgator and they gave me these options for my VPS server: install for free Tom Cat Java 5.5 or for a 75.00 install fee, install Tom Cat Java vers 6 or 7. Here is the next surprise they tell me: My VPS server (and BTW way, they they can't run Java on a shared server because it is too resource hungry, only on VPS or dedicated servers) only has 800MB of ram and they recommend 2MB at a greatly increased monthly cost! I told them to install 5.5 and I'll see how the performance is on my server. If it turns out I don't have enough ram, I don't think I want to pay 50.00 per month more for enough server memory just to run Tom Cat Java. I'll just have to forget about trying to implement C2DM on a Linux server.
Erel B4X founder Staff member Licensed User Longtime User May 22, 2012 #13 This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder. Upvote 0
This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder.
rfresh Well-Known Member Licensed User Longtime User May 22, 2012 #14 Erel said: This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder. Click to expand... Thanks for info. They already installed Java. I notice when I unregisted my device, it's record get deleted from my database but not when I uninstall my app. Do we have any way to remove known orphan records? Upvote 0
Erel said: This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder. Click to expand... Thanks for info. They already installed Java. I notice when I unregisted my device, it's record get deleted from my database but not when I uninstall my app. Do we have any way to remove known orphan records?
rfresh Well-Known Member Licensed User Longtime User May 23, 2012 #15 Erel said: This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder. Click to expand... What files do I need to copy to my Linux server? The .jar file and what about the config.txt file and the oauth.txt file? I'm having a terrible time getting the PHP script to call the .jar file successfully and am wondering if I am missing other files...right now I only have the .jar file copied over to the Linux server. Thanks... Upvote 0
Erel said: This Java app will not take more than 16mb. You do not need them to install anything. Just download the Java JRE and unzip it in a folder. Click to expand... What files do I need to copy to my Linux server? The .jar file and what about the config.txt file and the oauth.txt file? I'm having a terrible time getting the PHP script to call the .jar file successfully and am wondering if I am missing other files...right now I only have the .jar file copied over to the Linux server. Thanks...
Erel B4X founder Staff member Licensed User Longtime User May 23, 2012 #16 There is no "uninstall" event which you can handle. What files do I need to copy to my Linux server? Click to expand... The jar file and config.txt. I recommend you to first get it working from the shell and only then tie it with the PHP script. Upvote 0
There is no "uninstall" event which you can handle. What files do I need to copy to my Linux server? Click to expand... The jar file and config.txt. I recommend you to first get it working from the shell and only then tie it with the PHP script.