|
|
07-17-2008, 10:04 AM
|
#1
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
Sockets with Blackberry?
Please Login to Remove!
I'm working in a program, but i also have many doubts about it and hopefully you guys can help me with that...
This program would basically just sit there, and have a list of "names" or whatever...it would wait until it receive some kinda of "data", from a Computer, or from another phone... the only way i thought about doing it was to use sockets
i would make an app, for the phone to receive data...i would make another app for the computer to send data...and i would make another app for other phones to send data...
Now first i wanted to know if that is possible? or if there is any other way i could do it without using sockets?
and the phone, sinse it's connected to the internet, does it have an personal IP? or how do i find the phone using a computer?
hope someone can help me... ._.
|
Offline
|
|
07-17-2008, 10:37 AM
|
#2
|
Talking BlackBerry Encyclopedia
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
|
one of the ways suggested here earlier was to send data per e-mail and write a messagelistener to listen for the "special" messages and process them
|
Offline
|
|
07-17-2008, 11:06 AM
|
#3
|
Talking BlackBerry Encyclopedia
Join Date: May 2008
Model: 8110
PIN: N/A
Carrier: AT&T
Posts: 393
|
Would the Web Signals API help?
__________________
/\/\\/\/
|
Offline
|
|
07-17-2008, 11:15 AM
|
#4
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
uhmmm
don't even know what's that...
but the email thing sounds like an amazing idea...
but how do i add a listener for the email?
can you put a small example for me or something?
|
Offline
|
|
07-18-2008, 08:03 AM
|
#5
|
BlackBerry Extraordinaire
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
|
Have a look at the Blackberry Developers Knowledge Base article DB-00153. This message listening is an effective technique.
If you can use a BES or Unite server there is also the push listener described in DB-00434 for the Blackberry side, other articles describe the server side.
Web Signals, that MBW has been trumpeting, is a newly released protocol from RIM. There is very little hard information available but presumably it is the BIS equivalent of the push protocol supported by BES and Unite, it is similar if not identical to the facilities used by the various channel content providers to push things like the weather or sports scores to Blackberries.
Getting access to the Web Signals API is not as straight forward as is setting up a BES or Unite server. I have just started the process and will let the community know if I find out anything of interest.
|
Offline
|
|
07-18-2008, 09:43 AM
|
#6
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
so...here's what's happening
i'm trying to add the inboxFolder in a listener, so i can keep track of all the emails that the phone is going to receive
now i'm getting a bunch of errors, and i'm not sure of how can i solve it, so if anyone can help me please...
here is the part of the code that actually metters:
Code:
[...]
public static void main(String[]args) {
try {
Store s = Session.waitForDefaultSession().getStore();
store.addFolderListener(new FolderListener() {
public void messagesAdded(FolderEvent e) {
if( e.getMessage().isInbound() == true )
{
//message is a new received message
//perform some task here
}
}
//implement other FolderListener methods
//...
});
Folder[] folders = s.list(Folder.INBOX);
Folder inbox = folders[0];
inbox.addFolderListener(this);
}
catch (Exception e) {
}
Testdebugger n = new Testdebugger();
n.enterEventDispatcher();
}
and here are the errors i'm getting:
Quote:
Building dd
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe -quiet import=..\lib\net_rim_api.jar codename=dd dd.rapc warnkey=0x52424200;0x52525400;0x52435200 "C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java"
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:12: cannot find symbol
symbol : class event
location: package net.rim.blackberry.api.mail
import net.rim.blackberry.api.mail.event;
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:14: package net.rim.blackberry.api.main does not exist
import net.rim.blackberry.api.main.Message;
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:23: <anonymous com.rim.samples.device.helloworlddemo.Testdebugger $1> is not abstract and does not override abstract method messagesRemoved(net.rim.blackberry.api.mail.event. FolderEvent) in net.rim.blackberry.api.mail.event.FolderListener
public void messagesAdded(FolderEvent e) {
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:22: cannot find symbol
symbol : variable store
location: class com.rim.samples.device.helloworlddemo.Testdebugger
store.addFolderListener(new FolderListener() {
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:35: non-static variable this cannot be referenced from a static context
inbox.addFolderListener(this);
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:35: addFolderListener(net.rim.blackberry.api.mail.even t.FolderListener) in net.rim.blackberry.api.mail.Folder cannot be applied to (com.rim.samples.device.helloworlddemo.Testdebugge r)
inbox.addFolderListener(this);
^
6 errors
Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d C:\DOCUME~1\PETROB~1\LOCALS~1\Temp\rapc_31758c2e.d ir -bootcl ...
Error while building project
|
so yea
anyone has any idea of what should i do?
|
Offline
|
|
07-18-2008, 09:52 AM
|
#7
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
sorry...
i fixed most of the problems
but i still have two that i can't figure out
take a look at the thing now :
CODE:
Code:
package com.rim.samples.device.helloworlddemo;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.system.EventLogger;
import net.rim.blackberry.api.mail.Session;
import net.rim.blackberry.api.mail.Store;
import net.rim.blackberry.api.mail.Folder;
import net.rim.blackberry.api.mail.event.FolderListener;
import net.rim.blackberry.api.mail.event.FolderEvent;
final class Testdebugger extends UiApplication implements FolderListener {
public static void main(String[]args) {
try {
Store s = Session.waitForDefaultSession().getStore();
s.addFolderListener(new FolderListener() {
public void messagesAdded(FolderEvent e) {
if( e.getMessage().isInbound() == true )
{
//message is a new received message
//perform some task here
}
}
public void messagesRemoved(FolderEvent e) {
}
//implement other FolderListener methods
//...
});
Folder[] folders = s.list(Folder.INBOX);
Folder inbox = folders[0];
inbox.addFolderListener(this);
}
catch (Exception e) {
}
Testdebugger n = new Testdebugger();
n.enterEventDispatcher();
}
Testdebugger() {
pushScreen(new TestScreen());
}
}
final class TestScreen extends MainScreen {
public TestScreen() {
LabelField title = new LabelField ("OMG IT WORKS", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
}
}
Build:
Code:
Building dd
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe -quiet import=..\lib\net_rim_api.jar codename=dd dd.rapc warnkey=0x52424200;0x52525400;0x52435200 "C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java"
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:16: com.rim.samples.device.helloworlddemo.Testdebugger is not abstract and does not override abstract method messagesRemoved(net.rim.blackberry.api.mail.event.FolderEvent) in net.rim.blackberry.api.mail.event.FolderListener
final class Testdebugger extends UiApplication implements FolderListener {
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:35: non-static variable this cannot be referenced from a static context
inbox.addFolderListener(this);
^
2 errors
Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d C:\DOCUME~1\PETROB~1\LOCALS~1\Temp\rapc_314d5b0c.dir -bootcl ...
Error while building project
|
Offline
|
|
07-18-2008, 10:27 AM
|
#8
|
BlackBerry Extraordinaire
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
|
You must have a concrete implementation of the abstract method messagesRemoved(). If you are not monitoring the removal of messages, then just create an empty method.
|
Offline
|
|
07-18-2008, 10:32 AM
|
#9
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
ok, i did that and received another kind of error.
here it goes
Code:
final class Testdebugger extends UiApplication implements FolderListener {
^
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:35: non-static variable this cannot be referenced from a static context
inbox.addFolderListener(this);
^
and all i changed from the previous code was that i added:
Code:
public void messagesRemoved(FolderEvent e) {
}
|
Offline
|
|
07-18-2008, 10:44 AM
|
#10
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
ok..i almost solved everything
it's only one left, but i don't know what to do with it
look:
Code:
package com.rim.samples.device.helloworlddemo;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.system.EventLogger;
import net.rim.blackberry.api.mail.Session;
import net.rim.blackberry.api.mail.Store;
import net.rim.blackberry.api.mail.Folder;
import net.rim.blackberry.api.mail.event.FolderListener;
import net.rim.blackberry.api.mail.event.FolderEvent;
final class Testdebugger extends UiApplication implements FolderListener {
public static void main(String[]args) {
Testdebugger n = new Testdebugger();
n.enterEventDispatcher();
}
Testdebugger() {
Store s;
try {
s = Session.waitForDefaultSession().getStore();
s.addFolderListener(new FolderListener() {
public void messagesAdded(FolderEvent e) {
if( e.getMessage().isInbound() == true )
{
//message is a new received message
//perform some task here
}
}
public void messagesRemoved(FolderEvent e) {
}
//implement other FolderListener methods
//...
});
}
catch (Exception e) {
}
Folder[] folders = s.list(Folder.INBOX);
Folder inbox = folders[0];
inbox.addFolderListener(this);
pushScreen(new TestScreen());
}
}
final class TestScreen extends MainScreen {
public TestScreen() {
LabelField title = new LabelField ("OMG IT WORKS", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
}
}
I moved almost all the main to the constructor
so that i could use the (this).
but now look at the error i'm getting:
Code:
C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin\Testdebugger.java:16: com.rim.samples.device.helloworlddemo.Testdebugger is not abstract and does not override abstract method messagesRemoved(net.rim.blackberry.api.mail.event.FolderEvent) in net.rim.blackberry.api.mail.event.FolderListener
final class Testdebugger extends UiApplication implements FolderListener {
^
againt saying that i didn't overrite the messagesRemoved...
BUT I DID :(
i don't know where to put it anymore
|
Offline
|
|
07-18-2008, 10:59 AM
|
#11
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
oh...and i got one other question that is paralel...
the thing is...i moved everything to the constructor now...
is it still going to run as soon as the blackberry goes one? and it's going to still keep track of all the emails the person receives?
|
Offline
|
|
07-22-2008, 04:45 PM
|
#12
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
Quote:
Originally Posted by hrbuckley
Have a look at the Blackberry Developers Knowledge Base article DB-00153. This message listening is an effective technique.
If you can use a BES or Unite server there is also the push listener described in DB-00434 for the Blackberry side, other articles describe the server side.
Web Signals, that MBW has been trumpeting, is a newly released protocol from RIM. There is very little hard information available but presumably it is the BIS equivalent of the push protocol supported by BES and Unite, it is similar if not identical to the facilities used by the various channel content providers to push things like the weather or sports scores to Blackberries.
Getting access to the Web Signals API is not as straight forward as is setting up a BES or Unite server. I have just started the process and will let the community know if I find out anything of interest.
|
How does BES or Unite server work? and how do i know if i can use that?
is that something special that depends on the BlackBerry cause some have BES, or what?
|
Offline
|
|
07-22-2008, 05:07 PM
|
#13
|
Thumbs Must Hurt
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
|
A couple quick comments and I'm not trying to jerk.
You really need to learn the java language fundamentals, specifically the concepts of inheritance and polymorphism. The stuff you're working on right now is way over your head, but it's good you're trying to learn.
Also to any admins, the number of views on this thread should certainly turn heads... it's up to 16,000 or so and it was created just a couple days ago, which insinuates to me someone is pinging it with a bot.
|
Offline
|
|
07-23-2008, 07:34 AM
|
#14
|
Thumbs Must Hurt
Join Date: Apr 2006
Location: Boston
Model: 8900
Carrier: AT&T
Posts: 98
|
Java Coding
Hi!
This may be a little long, so take some No-Doz or some Jolt and bear with me.
Your "TestDebugger" class is declared to implement "FolderListener". This means that the methods declared by FolderListener are expected (by the compiler) to be implemented as methods of TestDebugger. So if the FolderListener interface declares a method of "public void messagesAdded( FolderEvent e )", then there must be a method implemented in TestDebugger with that same signature. Without it, the compiler will throw a hissy-fit because you promised it that TestDebugger would comply with the implementation declared in FolderListener, and then you reneged on your promise.
In your TestDebugger constructor, you are creating a new FolderListener() on the fly. You are adding the implementation of "messagesAdded" on the fly. This is not a bad thing, but it then leaves open the question of why you need TestDebugger to implement the FolderListener interface, since you're creating an OTF class to do just that. Then, just before your call to pushScreen at the end of the constructor, you're also adding another FolderListener to the session, the TestDebugger object that's just being created (note: in general, you want to shy away from adding "this" to potentially some other process while in the constructor: if it gets used by the other process before the constructor is completed, Bad Things can happen).
If you want TestDebugger to be a FolderListener:
- Remove the ad hoc FolderListener you're creating on the fly
- Implement the FolderListener interface methods within TestDebugger as methods of TestDebugger
- At the end of the TestDebugger constructor, add "this" to the session as a FolderListener
If TestDebugger is your main application class, you might consider creating a TDFolderListener class, whose job it is to act as a FolderListener. TDFolderListener could maintain a reference to the TestDebugger class (pass it in as a param to its constructor), and call public methods of TestDebugger whenever it responds to a FolderListener method being called on it. Separation of code tends to reduce problems in the sense that each code module does one thing and one thing only, and thus is usually easier to get working and to debug (if it's not working).
One more thing to be wary of: Session.waitForDefaultSession() is a blocking call. This means that the thread containing it will block execution until it returns. Usually this happens in a few microseconds. However, the BlackBerry OS does not appreciate applications that - effectively - hang in their main thread of execution. So you may need a separate thread that handles setting up the FolderListener stuff, which even more suggests creating a completely separate class just to be the FolderListener.
Good Luck!
Cheers,
karl
__________________
Karl G. Kowalski
---------------
Owns a RAZR
Develops for BlackBerry
So next phone will be........an iPhone 3G!
|
Offline
|
|
07-23-2008, 08:09 AM
|
#15
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
Quote:
Originally Posted by CELITE
A couple quick comments and I'm not trying to jerk.
You really need to learn the java language fundamentals, specifically the concepts of inheritance and polymorphism. The stuff you're working on right now is way over your head, but it's good you're trying to learn.
Also to any admins, the number of views on this thread should certainly turn heads... it's up to 16,000 or so and it was created just a couple days ago, which insinuates to me someone is pinging it with a bot.
|
even though you're not trying to be a jerk you were.
this is a forum to help people and with your post you didn't help ANYONE, just created one more message to be left in this post...
don't even come talk about my post, i'm trying to get my help here
admins should ban this kind of people that think they are smart, but can't help anyone...
step out then and leave for the nice (and smart) people to help me, because obviously you can only say bad stuff about things.
|
Offline
|
|
07-23-2008, 08:13 AM
|
#16
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
Quote:
Originally Posted by holy3daps
Hi!
This may be a little long, so take some No-Doz or some Jolt and bear with me.
Your "TestDebugger" class is declared to implement "FolderListener". This means that the methods declared by FolderListener are expected (by the compiler) to be implemented as methods of TestDebugger. So if the FolderListener interface declares a method of "public void messagesAdded( FolderEvent e )", then there must be a method implemented in TestDebugger with that same signature. Without it, the compiler will throw a hissy-fit because you promised it that TestDebugger would comply with the implementation declared in FolderListener, and then you reneged on your promise.
In your TestDebugger constructor, you are creating a new FolderListener() on the fly. You are adding the implementation of "messagesAdded" on the fly. This is not a bad thing, but it then leaves open the question of why you need TestDebugger to implement the FolderListener interface, since you're creating an OTF class to do just that. Then, just before your call to pushScreen at the end of the constructor, you're also adding another FolderListener to the session, the TestDebugger object that's just being created (note: in general, you want to shy away from adding "this" to potentially some other process while in the constructor: if it gets used by the other process before the constructor is completed, Bad Things can happen).
If you want TestDebugger to be a FolderListener:
- Remove the ad hoc FolderListener you're creating on the fly
- Implement the FolderListener interface methods within TestDebugger as methods of TestDebugger
- At the end of the TestDebugger constructor, add "this" to the session as a FolderListener
If TestDebugger is your main application class, you might consider creating a TDFolderListener class, whose job it is to act as a FolderListener. TDFolderListener could maintain a reference to the TestDebugger class (pass it in as a param to its constructor), and call public methods of TestDebugger whenever it responds to a FolderListener method being called on it. Separation of code tends to reduce problems in the sense that each code module does one thing and one thing only, and thus is usually easier to get working and to debug (if it's not working).
One more thing to be wary of: Session.waitForDefaultSession() is a blocking call. This means that the thread containing it will block execution until it returns. Usually this happens in a few microseconds. However, the BlackBerry OS does not appreciate applications that - effectively - hang in their main thread of execution. So you may need a separate thread that handles setting up the FolderListener stuff, which even more suggests creating a completely separate class just to be the FolderListener.
Good Luck!
Cheers,
karl
|
yea, that's very helpful, thank you
i also didn't read a lot about FolderListener, i just tried to implement it in my main class, which didn't end up pretty well...
but thanks for the help dude, i'll try that
|
Offline
|
|
07-23-2008, 04:59 PM
|
#17
|
Thumbs Must Hurt
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
|
Quote:
Originally Posted by Aiwa
even though you're not trying to be a jerk you were.
this is a forum to help people and with your post you didn't help ANYONE, just created one more message to be left in this post...
don't even come talk about my post, i'm trying to get my help here
admins should ban this kind of people that think they are smart, but can't help anyone...
step out then and leave for the nice (and smart) people to help me, because obviously you can only say bad stuff about things.
|
Hey hey, no need to get angry. I'm trying to help you out here! I simply deduced from your posts about those compiler issues that there might be some basics you're missing.
All I'm saying is without the fundamentals, it will be difficult if not impossible for you to understand what's going on!
Here are some links that can get you started:
javabeginner.com | Table of contents -- An excellent java fundamentals tutorial
Livelink - Redirection - you can get at many useful blackberry articles here
For reference, here is some code that will do what you're trying to do with a step by step explanation:
Code:
class FolderListenerMain extends UiApplication {
private MainScreen _mainScreen;
private LabelField _notifyField;
public static void main( String[] args ) {
// Create the UiApplication object and register it with the system
// to start receiving UI events.
FolderListenerMain app = new FolderListenerMain();
app.enterEventDispatcher();
}
FolderListenerMain() {
// Create a new thread so the event dispatch thread doesn't block
// when waitForDefaultSession() is invoked.
Thread loadStoreThread = new Thread( new Runnable() {
public void run() {
// The mail store
Store s = null;
try {
// Get the default mail session (if corporate this would be
// a session associated with a BES mail servicebook record)
s = Session.waitForDefaultSession().getStore();
if ( s != null ) {
// Register the folder listener with the Store
s.addFolderListener( new FolderListener() {
// Called when any message is added to the store
public void messagesAdded( FolderEvent e ) {
Message m = e.getMessage();
if ( m != null && m.isInbound() ) {
// Have to make sure this invoke later actually ends up on
// our application's event queue. Simply calling UiApplication.getUiApplication
// is not sufficient because the application we get back is not our own.
FolderListenerMain.this.invokeLater( new Runnable() {
public void run() {
_notifyField.setText( "Message Received" );
}
});
}
}
// Called when any message is removed from the store
public void messagesRemoved( FolderEvent e ) {
FolderListenerMain.this.invokeLater( new Runnable() {
public void run() {
_notifyField.setText( "Message Deleted" );
}
});
}
});
}
}
catch ( Exception e ) {
; // It would probably be good to catch the specific exception rather than a general one
}
}
});
_mainScreen = new MainScreen();
_mainScreen.setTitle( "FolderListener Test" );
_notifyField = new LabelField( "Waiting for message..." );
_mainScreen.add( _notifyField );
pushScreen( _mainScreen );
loadStoreThread.start();
}
}
I hope this helps! (Maybe I'm not that bad a guy? :P)
Last edited by CELITE; 07-23-2008 at 05:30 PM..
|
Offline
|
|
07-24-2008, 08:54 AM
|
#18
|
Thumbs Must Hurt
Join Date: Jul 2008
Model: 7100T
PIN: N/A
Carrier: Programmer
Posts: 50
|
well...i took a class in high school for basics for java, so i know enogh of basics of java
but JDE doesn't use the normal java, the basic classes or anything like that
and that's how i'm having more problems...
and the way you said it before wasn't very nice.
__________________
--------------------
Carlos Mastrangelo
--------------------
|
Offline
|
|
07-24-2008, 12:07 PM
|
#19
|
Thumbs Must Hurt
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
|
The blackberry development API includes the basic implementation of the CLDC classes plus RIM's API extensions.
In that sense it is very different from the Java SE framework that you're used to, but all the fundamental design patterns and development concepts still hold strong (with the exceptions of reflection and remote method invocation).
So for basic development, there's no difference in the fundamentals, which is the beauty of RIM's framework. In contrast, I find MIDP to be sluggish and limited, especially for UI development.
|
Offline
|
|
|
|