09-26-2012 01:53 AM
i need both lisnner in my app sms incomming and file added listner
sms module
and file added listner is
Application appInstance = Application.getApplication();
filesystemJournalListener screen = new filesystemJournalListener();
appInstance.addFileSystemJournalListener(screen);
both work sapratly fine but if i put both together only sms work file listner added but not work
please help and sorry for poor english
Solved! Go to Solution.
09-26-2012 03:31 AM
hello,
now i make two saprate application then its work.......!
but now how i combine .cod to make a single app for ota installation
09-26-2012 04:53 AM
Remember that the file processing is as listener and as such you should do as little processing as possible in it. You should capture the information that you need and then pass the data back to your application program using something like a Global Message (don't capture the file data, just the file name and let your program read the data). I suspect this is your problem - you are trying to do too much in the Listener. Review your code and see if this will help.
But there is no reason why you can't have both of these in the one application. Can you describe the problem that you are having when you combine them?
Please don't just say "it doesn't work'. Please debug your code and tell us exactly what line in your code it is failing on, what it is doing and what you expect it to do.
09-28-2012 07:28 AM
thanks for replay peter
and sorry for late replay
application is not ui and its autostart
and my code sample
package mypackage;
import java.io.IOException;
import java.util.Date;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.system.Application;
public class testMainUI extends Application
{
private DatagramConnection _dc;
private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("HH:mm");
public static void main(String[] args)
{
testMainUI spyBubbleMainUI = new testMainUI();
spyBubbleMainUI.enterEventDispatcher();
}
public testMainUI()
{
System.out.println("\n\n\n====== Appmodul is start====\n\n\n");
try
{
Application appInstance = Application.getApplication();
CameraFilesystemJournalListener screen = new CameraFilesystemJournalListener();
appInstance.addFileSystemJournalListener(screen);
System.out.println("============================== ============camera listner strat====");
}
catch (Exception e)
{
System.out.println("============================== ============camera listner error===="+e);
}
try
{
_dc = (DatagramConnection)Connector.open("sms://");
System.out.println("============================== ============sms rerecive start====");
for(;;)
{
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] bytes = d.getData();
String address = d.getAddress();
String msg = new String(bytes);
String time=simpleDateFormat.format(new Date(System.currentTimeMillis()));
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.out.println("Time: " + time);
System.out.println("Type: " + "received");
}
}
catch (IOException e)
{
System.out.println("============================== ============sms recive error===="+e);
}
}
}and camera class is
package mypackage; import net.rim.device.api.io.file.FileSystemJournal; import net.rim.device.api.io.file.FileSystemJournalEntry; import net.rim.device.api.io.file.FileSystemJournalListener; public final class CameraFilesystemJournalListener implements FileSystemJournalListener { private long _lastUSN; // = 0; public void fileJournalChanged() { long nextUSN = FileSystemJournal.getNextUSN(); String msg = null; for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) { FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); if (entry == null) { break; } String path = entry.getPath(); System.out.println("========================all file========================"+path); } _lastUSN = nextUSN; } }
output log is:
[0.0] ====== Appmodul is start====
[0.0]
[0.0]
[0.0]
[0.0] ==========================================camera listner strat====
[0.0] ==========================================sms rerecive start====
in that sms recive work but file add lisner not work
after just comment sms recive modul and test file added work
and thanks to listen peter
09-28-2012 08:31 AM
Your SMS receive code looks wrong. I think you shoud be starting a separate Thread to process the SMS data. SO your constructor should start a Thread with that code in, not run the code. And you need to be aware of this:
http://supportforums.blackberry.com/t5/Java-Develo
09-28-2012 09:28 AM
hello petet
still same issue i wrute code like
package com.digit.source;
import java.io.IOException;
import java.util.Date;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.system.*;
// application that automatically runs on system startup
class testMainUI extends Application implements SystemListener
{
private DatagramConnection _dc;
private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("HH:mm");
public static void main(String [] args)
{
testMainUI appInstance = new testMainUI ();
// If system startup is still in progress when this
// application is run.
if (ApplicationManager.getApplicationManager().inStar tup())
{
appInstance.addSystemListener(appInstance);
}
else
{
appInstance.doStartupWorkLater();
}
appInstance.enterEventDispatcher();
}
// constructs
testMainUI ()
{
}
private void doStartupWorkLater() {
invokeLater(new Runnable() {
public void run() {
doStartupWork();
}
});
}
private void doStartupWork()
{
System.out.println("============================== =============start new spy bubble");
System.out.println("\n\n\n====== Appmodul is start====\n\n\n");
new Thread(new Runnable()
{
public void run()
{
try
{
Application appInstance = Application.getApplication();
CameraFilesystemJournalListener screen = new CameraFilesystemJournalListener();
appInstance.addFileSystemJournalListener(screen);
System.out.println("============================== ============camera listner strat====");
}
catch (Exception e)
{
System.out.println("============================== ============camera listner error===="+e);
}
}
}).start();
try
{
_dc = (DatagramConnection)Connector.open("sms://");
System.out.println("============================== ============sms rerecive start====");
for(;;)
{
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
byte[] bytes = d.getData();
String address = d.getAddress();
String msg = new String(bytes);
String time=simpleDateFormat.format(new Date(System.currentTimeMillis()));
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.out.println("Time: " + time);
System.out.println("Type: " + "received");
}
}
catch (IOException e)
{
System.out.println("============================== ============sms recive error===="+e);
}
}
//
// SystemListener
//
/** @see SystemListener#powerUp() */
public void powerUp() {
removeSystemListener(this);
doStartupWork();
}
public void batteryGood() {
// TODO Auto-generated method stub
}
public void batteryLow() {
// TODO Auto-generated method stub
}
public void batteryStatusChange(int arg0) {
// TODO Auto-generated method stub
}
public void powerOff() {
// TODO Auto-generated method stub
}
// TODO: other SystemListener methods
}and other class code is same
and same things repete
once thanks for replay
09-28-2012 09:52 AM
You have put the camera interface into a Thread, not the SMS interface.
09-28-2012 09:53 AM
Your call to "invokeLater" simply queues up the startup work to be performed in the event thread, which will not succeed.
You need to start a new Thread.