BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-17-2008, 02:24 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default DeviceInfo.getDeviceId() gets Wrong PIN

Please Login to Remove!

Hi,
I used the code snippet below to retrieve my device PIN and got wrong values for both the simulator and real device (8310); the retrieved PIN was a 9 digit int (all are numbers) instead of an 8 digit string of the format 251CE***. What am I doing wrong?

Pls help

====== CODE STARTS========
import net.rim.device.api.system.DeviceInfo.*;

//retrieve device PIN
int _PIN = DeviceInfo.getDeviceId();

//convert INT to String
String sPIN = ""+ _PIN;

//append PIN to URL
String _url = "http://mypage.com?PIN=";
StringBuffer sb = new StringBuffer();
sb.append(_url);
sb.append(sPIN);
String full_URL = sb.toString();

//display PIN and URL on screen
RichTextField _path1 = new RichTextField(sPIN);
RichTextField _path2 = new RichTextField(full_URL);
add(_path1);
add(_path2);

=======CODE ENDS============
Offline  
Old 12-17-2008, 02:42 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You need to convert the int to a string in hexadecimal format.

For example, 254 becomes EF, etc.
Offline  
Old 12-17-2008, 02:43 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thx, I was able to solve it with this:

//retrieve the device PIN
String _PIN = (Integer.toString(DeviceInfo.getDeviceId(),16)).to UpperCase();
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.