Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl
Accepted Solution

FileSystemJournalListener and SMS incoming not work together

i need both lisnner in my app sms incomming and file added listner

 

sms module

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To_...

 

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

Please use plain text.
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: FileSystemJournalListener and SMS incoming not work together

hello,

 

now i make two saprate application then its work.......!

 

but now how i combine .cod to make a single app for ota installation

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: FileSystemJournalListener and SMS incoming not work together

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. 

Please use plain text.
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: FileSystemJournalListener and SMS incoming not work together

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

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: FileSystemJournalListener and SMS incoming not work together

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-Development/Write-safe-initialization-code/ta-p/444795

Please use plain text.
Regular Contributor
hitesh171285
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: FileSystemJournalListener and SMS incoming not work together

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().inStartup()) 
		{
			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

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: FileSystemJournalListener and SMS incoming not work together

You have put the camera interface into a Thread, not the SMS interface.

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: FileSystemJournalListener and SMS incoming not work together

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.

 

Please use plain text.