Wednesday, November 24, 2010

Converting Datetime in different timezones in Blackberry




Greetings,

I was working on a logic in Blackberry application where I had to show time on screen in two different timezones together where one being the default IST timezone and another being PST timezone. At first I stuck but after reading couple of forum threads I could manage to do so. I am sharing the approach today.

First of we need to find list of available timezone and their IDs in order to make it work.

A simple code to get list of timezone available on Blackberry platform could be like this:

String[] supportedTimezoneIDs = TimeZone.getAvailableIDs();
for(int i=0; i<supportedTimezoneIDs.length; i++){

System.out.println(supportedTimezoneIDs[i]);
}


It will print list of timezones like:

Pacific/Kwajalein
Pacific/Midway
Pacific/Honolulu
America/Anchorage
America/Tijuana
America/Los_Angeles
America/Phoenix
America/Denver
America/Tegucigalpa
America/Tegucigalpa_2
America/El_Salvador
America/Regina
America/Chicago
America/Mexico_City
America/Mexico_City_2
America/Bogota
America/Indianapolis
America/New_York
America/Caracas
America/La_Paz
America/Manaus
America/Santiago
America/Halifax
America/St_Johns
America/Montevideo
America/Guyana
America/Buenos_Aires
America/Sao_Paulo
America/Godthab
America/South_Georgia
Atlantic/Cape_Verde
Atlantic/Azores
GMT
Europe/Dublin
Africa/Luanda
Europe/Amsterdam
Europe/Belgrade
Europe/Brussels
Europe/Belgrade Yugoslavia(YU)
Africa/Windhoek
Asia/Amman
Africa/Harare
Asia/Jerusalem
Europe/Minsk
Africa/Cairo
Asia/Beirut
Europe/Athens
Europe/Helsinki
Asia/Kuwait
Africa/Nairobi
Asia/Baghdad
Europe/Moscow
Asia/Tehran
Asia/Tbilisi
Asia/Muscat
Asia/Baku
Asia/Yerevan
Asia/Caucasus
Asia/Kabul
Asia/Karachi
Asia/Tashkent
Asia/Yekaterinburg
Asia/Calcutta
Asia/Colombo
Asia/Katmandu
Asia/Dhaka
Asia/Almaty
Asia/Rangoon
Asia/Bangkok
Asia/Krasnoyarsk
Asia/Hong_Kong
Asia/Kuala_Lumpur
Australia/Perth
Asia/Taipei
Asia/Irkutsk
Asia/Tokyo
Asia/Seoul
Asia/Yakutsk
Australia/Darwin
Australia/Adelaide
Pacific/Guam
Asia/Vladivostok
Australia/Hobart
Australia/Brisbane
Australia/Sydney
Asia/Magadan
Pacific/Fiji
Pacific/Auckland
Pacific/Tongatapu



To get default timezone of the device:

System.out.println("Default TimeZoneID: "+Calendar.getInstance().getTimeZone().getID());

It will print the timezone ID that you can use for further conversion.

Now here is my logic in which I first check if the default timezone is IST, then I want a converted PST time or vice versa.

long timestamp = System.currentTimeMillis();
Calendar defaultCalendar = Calendar.getInstance(); //it gives time in default timezone set on device.
DateFormat dtFormatter = new SimpleDateFormat("E, yyyy-MM-dd HH:mm");

if(defaultCalendar.getTimeZone().getID().trim().equalsIgnoreCase("Asia/Calcutta")){
//This is now PST calendar instance
Calendar pstCal = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
// set the curent time, this need to be currenttimemills since in BB and Java
// this is a number of milisecond from epoch. When it is set in calendar with
// timezone, it will pick the date time of that timezone.
pstCal.setTime(new Date(System.currentTimeMillis()));

// this is another tricky part I found. Using format and passing the calendar
// instance is what gives the right result.
// I tried using formatLocal but it always gives datetime as per default timezone
// of the system and as in my case it was always IST, so no conversion
// happens for PST.
String formattedDate2 = dtFormatter.format(pstCal, new StringBuffer(), null).toString(); //dtFormatter.formatLocal(timestamp);
dateTimeField2.setText(formattedDate2 + " PST");

String formattedDate1 = dtFormatter.formatLocal(timestamp);
dateTimeField1.setText(formattedDate1 + "IST");

} else if(defaultCalendar.getTimeZone().getID().equalsIgnoreCase("America/Los_Angeles")){
Calendar istCal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Calcutta"));
istCal.setTime(new Date(System.currentTimeMillis()));

String formattedDate2 = dtFormatter.format(istCal, new StringBuffer(), null).toString();//dtFormatter.formatLocal(timestamp);

dateTimeField2.setText(formattedDate2+" IST");
TimeZone tz = TimeZone.getDefault();
String formattedDate1 = dtFormatter.formatLocal(timestamp);
dateTimeField1.setText(formattedDate1+ "PST");
}

So this is how I converted the IST time into PST on Blackberry. I hope this would be of some help to people looking for the same.

Thanks,
Sameer.




Tuesday, November 16, 2010

On Device Debugging Blackberry OS 5.0 Not able to connect issue solution




Well as things are progressing, new OS updates are being released, new devices, new api and there comes new problems.

I have been facing an interesting issue with On Device Debugging with Blackberry 8900 running on OS 5.0 using Eclipse Blackberry plugin 1.1.2.

It was a strange and simple issue.. I was not able to connect to my device and hence was not able to debug on my device. As the problem was simple I thought the solution has to be simple.

When I used to configure Eclipse Plugin to connect to device, it used to compile, sign and connect to device, then it ask me to enter device password and then boom, nothing happens. On device screen it shows a simple message Debugger connection failed.

The solution was pretty simple. My device was password protected, so I just disabled the password and voila, am now able to connect to my device and debug the application successfully. Though while connecting to the device, the Eclipse Plugin used to ask me the password, so I was not guessing it could be a problem since it asked for password and I provided it, bot no it wasn't working.

After trying so many things unnecessarily, I figured the solution was quite simple. Sometimes a simple way and simple thinking is the only thing required to solve tedious issues.

Anyway, I'm sharing this small story to help people who may be scratching there heads with this small issue.

Happy debugging :)




Sunday, August 1, 2010

BEWARE: Phishing Email attack targeting Blackberry Developers.


BEWARE of Phishing email:

I have been getting this email couple of times, and each time I get this first thing I feels is oh wow.. someone is trying to hack my RIM account... I feel eager to know what went wrong.. I then look for links in email to know more or do something to save my account and I click the link..... Thats what anyone would do when they receive following email:

Dear ,

Recently, we noticed that you attempted to access your online profile. Unfortunately, your account has been locked, after an unsuccessful authentication procedure. To unlock your account, access our Career Section login page, click "Forgot your password?" and follow the instructions provided.
Please feel free to review and update your profile as often as you like. You may also sign up to receive automatic email notifications when jobs matching your skills and interests become available. To view a list of current job openings, click here.
Thank you for your interest in Research In Motion.


Best regards,
RIM Global Recruitment
Research In Motion


Replies to this message are undeliverable. Please do not reply.
Research In Motion (RIM), is a world leader in the mobile communications market, and has a history of developing breakthrough wireless solutions, such as the BlackBerry® wireless platform. To view our impressive BlackBerry solution products, please visit www.BlackBerry.com.


------------------------------------------------------------------


This is a PHISHING EMAIL and NOT FROM RESEARCH IN MOTION ltd.

BEWARE that someone is trying to do something wrong with you, but this email is phishing. Keep your eyes OPEN before opening this email.

You can see clearly that this emails is generated from wrong sources and NOT RESEARCH IN MOTION.

First of all, you must notice that it do not address you by your name, It says "Dear ," If you read it with your senses you would probably guess something is wrong with email, that is what I did. How come RIM telling me my account is blocked when they don't even know my Name?? Strange isn't it?

Second, To unlock your account, access our Career Section login page"???? What? Career Section? Login Page?? Unbelievably stupid idea, I have no Career Relation with RIM, yeah am Blackberry developer but I never applied for any Job post at RIM how come RIM ask me to access Career Section??? Insane. But its easy to understand if you read it carefully.

More over read the complete email they are talking about Job openings and stuff in this email. But its all FAKE. DO NOT Click any Link it may HURT YOU.

As soon as I figured it out, I did google on this email issue to see if anyone else talked about it or not. Unfortunately I didn't found anything useful and seems like many people are not aware about it or so.

BUT I found a post about RIM fixing some loop holes that some how relates to this phishing emails (I Guess). http://www.zdnet.com/blog/security/rim-plugs-blackberry-phishing-hole/4500

So be AWARE guys and do not get trapped.

Thanks,
~Sameer Nafdey


Wednesday, November 4, 2009

BlackBerry Model & Device detection from HTTP Request.


I was just going through some online documents regarding Blackberry browser and device detection stuff and found some useful information which might be useful to you when it comes to detect Blackberry Model by intercepting the HTTP Request Headers to know the user's device's capabilities. So here it is. Also check the rdf document at the link quoted below.

The browser reports the capabilities of the BlackBerry smartphone in the headers of the HTTP Request. The server hosting the application can examine these headers for the necessary information. The User-Agent header provided by the browser is in the format: BlackBerry/. For example, BlackBerry8800/4.2.1.

In addition to the User-Agent header, the profile header can also be used to access information about the capabilities of the BlackBerry smartphone. This header is actually a web address that the server can access for a Resource Description Framework (RDF) Extensible Markup Language (XML) document that fully describes the BlackBerry smartphone. An example of such a document can be found here:

http://www.blackberry.net/go/mobile/profiles/uaprof/8800/4.2.1.rdf



Regards,
Sameer.

Monday, November 2, 2009

Blackberry Device List with OS versions, Screen Resolution / Dimensions, Icon Sizes



Reference:
  1. BlackBerry Smartphones - UI Guidelines
  2. BlackBerry Device OS Checker tool
The Information above posted is updated up to November 02, 2009. This information is supposed to be the latest one, though please check once at RIM and/or more reliable sources around internet.

Monday, October 5, 2009

Intresting bug in Blackberry OS 4.6 Phone API

I was writing some logic to handling outgoing call, so I used PhoneListener and simply handled the callInitiated() method as follows.


public void callInitiated(int callid) {
PhoneCall call = Phone.getCall(callid);
String calledNumber = call.getDisplayPhoneNumber();
if (calledNumber != null && calledNumber.trim().length() > 0) {
if("15245".equals(calledNumber){
//--do something--
}else if("15246".equals(calledNumber){
//--do something--
}
}
}


The strange thing was it worked normally on OS 4.2, but when tried on OS 4.6 and higher, both conditions failed to match, even when the number was exactly same (i.e. 15245 or 15246). Later on when I investigated it further, I found the strange thing. The calledNumber was having a special character a.k.a LEFT-TO-RIGHT MARK in Unicode Character set. (for more info: read this)

When printed on console using SOP statement, it prints '?' and is int 8206. So I had to put a special logic to this special problem and solved it.

I hope this help someone having the same problem.

Cheerz
Sameer Nafdey

Tuesday, September 29, 2009

Solution : Unable to connect to Internet Blackberry simulator 8820 OS 4.2.0

Well as a seasoned Blackberry developer you'd probably have a lot of different JDE's and Simulators setup on your development machine like me. I ran through a problem with some configurations of JDE's and MDS and I would like to share it with all.

Background:
I have many variants of JDEs installed on my machine like JDE 4.2.0, 4.3.0, 4.5.0, 4.6.0 and 4.7 and yeah a lot of simulators of various Blackberry Handheld with different OS versions too. So while working on multiple projects I usually need to keep switching between different JDEs as most of the Blackberry developers would do. So I try to keep my development machine optimized with only required things installed and try to reuse software components.

This time I was trying to reuse the MDS Simulator that comes with JDE 4.3.0. I tried to use MDS of JDE 4.3.0 with JDE 4.2.0 by configuring the base path in MDS Tab of Preference configuration. It gets invoked properly from JDE 4.2.0 along with simulator when selected in the simulator config, though it do not get coupled properly with Simulator at run time. Which caused issue like I was not able to access MDS Service on simulator and obviously my applications were not able to connect too.

Solution:
I just remember that long ago I used to use Blackberry MDS Simulator 4.1.0 as a separate installation with JDE 4.2.0 that used to work well. I tried to reinstall the MDS Simulator 4.1.0 separately and configured with JDE 4.2.0 and it started working well.

So it made me think may be the JDE 4.2.0 only works with MDS 4.1.0, because somewhere I read on some forum that MDS that comes pre-installed with 4.5.0 and Higher is known as MDS-CS, which is some how different than previous MDS simulators, but infact JDE 4.3.0 comes with MDS Simulator not the MDS-CS so I thought it would work without an issue.

May be I am wrong because I'm not having much idea about the MDS Simulator specifically, but yeah it solved my problem so it feels great to me to share this info to all.

I hope it would help someone somewhere someday.

Wish you good luck.

Cheers
Sameer.
Support Wikipedia