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
Highlighted
Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone
Accepted Solution

Is there any listener to get email config status?

I want to send mail thorugh my app, but when i use this

store = Session.getDefaultInstance().getStore();
store.addSendListener(this);

 this will throw exception when no email is configured in my account, So i want to know when i configured email in my device is there any listener to fetch that registered email account?

 

Thanks & Regards

Developer
Posts: 16,985
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Is there any listener to get email config status?

You can listen to changes using a GlobalEventListener and the GUIDs outlined in http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/servicebook/ServiceBook.html

to find email addresses iterate over the service records of a service book.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Is there any listener to get email config status?

i am able to get email addresses using service book, but if there is no email configured then the main problem arises for me
Developer
Posts: 16,985
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Is there any listener to get email config status?

if there is no mail account you cannot send mail (with the standard mail api).
you could implement your own smtp or use a webservice or...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Is there any listener to get email config status?

Just to confirm the question here, I think the OP is asking if he can be notified when an email account is actually added. 

 

I am not aware of a listener that will do that, but then I have never looked.  If you have searched and not found one, then I suspect there is not one.  It would not be a commonly used listener so I can see why it would not be implemented.

 

Assuming there is no listener, then you can just test at regular intervals to find out. 

Developer
Posts: 16,985
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Is there any listener to get email config status?

As i have stated there are global events for all kind of events regarding service books, for example when one is added or changed.
All you have to do is to check if the added/changed service book contains a mail account.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Is there any listener to get email config status?

Ah, hadn't spotted that, good idea.

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Is there any listener to get email config status?

Can i get a little study material or some sample code regarding the same?
Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Is there any listener to get email config status?

Till now i have tried like this:

ServiceBook sb 	= ServiceBook.getSB();
ServiceRecord[] records = 	sb.findRecordsByCid("CMIME");
serviceConfiguration	= 	new ServiceConfiguration[records.length];
for (int i =0;i<records.length;i++)
{          
    serviceConfiguration[i]= new ServiceConfiguration(records[i]);
    System.out.println("ServiceConfiguration[i]----> " + serviceConfiguration[i]);
}
for(int i=0;i<serviceConfiguration.length;i++)
{
    Store store=Session.getInstance(serviceConfiguration[i]).getStore();
    System.out.println("Email : " + serviceConfiguration[i].getEmailAddress());
    store.addSendListener(this);
    Folder[] folders = store.list();
    System.out.println("Number of Folders :"+folders.length);
    Folder[] inboxes	=	store.list(Folder.INBOX);
    inboxes[0].addFolderListener(this);
    System.out.println("Number of Inboxes :"+inboxes.length);
    for(int j=0;j<inboxes.length-1;j++)
    {
	System.out.println("Loop : " + j);
	try
	{
	   Message[] messages =	inboxes[j].getMessages();
	   System.out.println("Message : "+messages[0].getSubject());
	   System.out.println("length : "+messages.length);
	}
	catch (Exception e)
	{
		System.out.println( "Exception...."+e);
	}
    }			
}

 but when no email account is configured it will not enter into any loop....  and if there is one email account configured i add a new email a/c then again only one email shows and listener added only to that..

Developer
Posts: 16,985
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Is there any listener to get email config status?

so add a listener for service books.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter