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
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry
Accepted Solution

How to check email is configured on device or not?? in Blackberry mobile device

Hello I am working on blackberry 9800 having native java language. I want to check in my application that whether mail address is configured on my device or not. I want that:

If (mail == Configured) { Mail is configured on device }

else (mail1=configures){Mail is not configured on device}

Please any one show me sample code, i have search so much,but i am not able to get the exact answer.
I am new to blackberry development

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to check email is configured on device or not?? in Blackberry mobile device

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: How to check email is configured on device or not?? in Blackberry mobile device

http://supportforums.blackberry.com/t5/Java-Development/Read-email-id-configured-in-device-in-the-ap...

I saw your post using KB... Kindly tell me in this code that i want to make dialog box "email not configured" if email is not configured on device..

Please plx tell me i am new to BB development, thats why i am not getting the answer of my problem exactly..Please help me out there.

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to check email is configured on device or not?? in Blackberry mobile device

"i am not getting the answer of my problem exactly.."

 

That is normal and there is no fun just cutting pasting existing code.  Creating your own is a better way to learn  isn't it? 

 

In this case I would rework one of the KB articles into a method that returned true or false depending on whether there was an email account on device.  Then you can choose  to display the dialog easily.

 

If you are struggling with Java, then this is not the right forum for you.  I recommend you get a book or go one a course. 

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: How to check email is configured on device or not?? in Blackberry mobile device

You are right Sir.I appreciate your help

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: How to check email is configured on device or not?? in Blackberry mobile device

String emailAddress;
                    try {
                            Session ourSession = Session.getDefaultInstance();
                            emailAddress = ourSession.getServiceConfiguration().getEmailAddress();
                        }
                    
                    catch ( Exception e )
                    {
                            emailAddress = null;
                            Dialog.alert(emailAddress+"======>email is not configured");
                            Dialog.alert(emailAddress);
                    }
                    if ( emailAddress != null && emailAddress.length() > 0 ) {

                        Dialog.alert(emailAddress+"=====>123");
                        Dialog.alert(emailAddress+"email is configured");
                        emailAddress = emailAddress.toLowerCase();
                                          }

 

Is this is correct??

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to check email is configured on device or not?? in Blackberry mobile device

It is not my call if it is right or not - it is your code and must meet your specifications.  But it is nothing like what I suggested. 

 

In this case the code you are using only checks the default email - there may be other email accounts configured, as indicated with this KB article that Simon pointed you at previously:

http://supportforums.blackberry.com/t5/Java-Development/Send-a-message-from-a-non-default-email-addr...

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: How to check email is configured on device or not?? in Blackberry mobile device

[ Edited ]

Sir I appriciate your quick response, I just want to know that in this example code, we are giving hard coded address, if their is another account in device joe@yahoo.com", "Joe".

How it is possible to get the required address which are available on device, like if i have Yahoo, and gmail. then I Should select gmail or yahoo for mail sending. Without giving hard coded address like joe@yahoo.com in the following KB example which you have mentioned.

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to check email is configured on device or not?? in Blackberry mobile device

Does this help?

 

        /**
        * Get all Email addresses associated with the device
        * @return - String array containing email addresses. 
        */
        public static String [] getOurEmailAddresses() {
                // Shared routine to get all email addresses associated with this BlackBerry
                try {
                        ServiceBook sb = ServiceBook.getSB();
                        ServiceRecord[] srs = sb.getRecords();
                        String [] possibleEmailAddress = new String [srs.length];
                        String emailAddress = null;
                        int emailAddressCounter = 0; // count of number actually found
                
                        for ( int cnt = srs.length - 1; cnt >= 0; --cnt) {
                                //identify the service record associated with a mail message service via a CID of 'CMIME'
                                if( srs[cnt].getCid().equals( "CMIME" )) {
                                        ServiceConfiguration sc = new ServiceConfiguration(srs[cnt]);
                                        if ( sc != null ) {
                                                emailAddress = sc.getEmailAddress();
                                                if ( emailAddress != null && emailAddress.length() > 0 ) {
                                                        // To be consistent, make sure email addresses are lower case
                                                        possibleEmailAddress[emailAddressCounter] = emailAddress.toLowerCase();
                                                        emailAddressCounter++;
                                                }
                                        }
                                }
                        }
                        // Now have in possibleEmailAddress, emailAddressCounter email's
                        if ( emailAddressCounter == 0 ) {
                                return null;
                        }
                        String [] returnEmailAddresses = new String [emailAddressCounter];
                        for ( int i = 0; i < emailAddressCounter; i++ ) {
                                returnEmailAddresses[i] = possibleEmailAddress[i];
                        }
                        return returnEmailAddresses;
                } catch (Exception e) {
                        return null;
                }
        }