Lets say you wish you make your application to attempt to make a call in Blackberry. This is how you do it.
PhoneArguments pa = null;
pa = new PhoneArguments(PhoneArguments.ARG_CALL,"67838763520");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, pa);
The bolded part is the number you wish to make a call to.
You might also want to check for any active calls before making a call. So here it is:
private static boolean gotActiveCall() {
boolean callExist = false;
if(Phone.getActiveCall() != null) {
callExist = true;
}
return callExist;
}
Wednesday, 29 April 2009
BlackBerryContact Names
Getting the name of a BlackBerryContact has been been this easy... :)
This method takes in a BlackBerryContact as the argument and would return the name as a String.
private String getDisplayName(BlackBerryContact contact) {
StringBuffer buf = new StringBuffer();
String[] name = contact.getStringArray(BlackBerryContact.NAME, 0);
//Get the prefix, first and last name
boolean found = false;
String nameseg;
// Catch each field separately to make sure we get any available fields
try {
if((nameseg = name[BlackBerryContact.NAME_PREFIX]) != null && nameseg.length() != 0) {
buf.append(nameseg);
found = true;
}
} catch(IndexOutOfBoundsException ignore) {}
try {
if ((nameseg = name[BlackBerryContact.NAME_GIVEN]) != null && nameseg.length() != 0) {
if(found) {
buf.append(' ');
buf.append(nameseg);
found = true;
}
}
} catch(IndexOutOfBoundsException ignore) {}
try {
if((nameseg = name[BlackBerryContact.NAME_FAMILY]) != null && nameseg.length() != 0) {
if (found) {
buf.append(' ');
}
buf.append(nameseg);
found = true;
}
} catch(IndexOutOfBoundsException ignore) {}
//This is to get the Company if no names are found under the Contact
try {
if (found == false) {
buf.append(contact.getString(BlackBerryContact.ORG, 0));
}
} catch(IndexOutOfBoundsException ignore) {}
return buf.toString();
}
This method takes in a BlackBerryContact as the argument and would return the name as a String.
private String getDisplayName(BlackBerryContact contact) {
StringBuffer buf = new StringBuffer();
String[] name = contact.getStringArray(BlackBerryContact.NAME, 0);
//Get the prefix, first and last name
boolean found = false;
String nameseg;
// Catch each field separately to make sure we get any available fields
try {
if((nameseg = name[BlackBerryContact.NAME_PREFIX]) != null && nameseg.length() != 0) {
buf.append(nameseg);
found = true;
}
} catch(IndexOutOfBoundsException ignore) {}
try {
if ((nameseg = name[BlackBerryContact.NAME_GIVEN]) != null && nameseg.length() != 0) {
if(found) {
buf.append(' ');
buf.append(nameseg);
found = true;
}
}
} catch(IndexOutOfBoundsException ignore) {}
try {
if((nameseg = name[BlackBerryContact.NAME_FAMILY]) != null && nameseg.length() != 0) {
if (found) {
buf.append(' ');
}
buf.append(nameseg);
found = true;
}
} catch(IndexOutOfBoundsException ignore) {}
//This is to get the Company if no names are found under the Contact
try {
if (found == false) {
buf.append(contact.getString(BlackBerryContact.ORG, 0));
}
} catch(IndexOutOfBoundsException ignore) {}
return buf.toString();
}
BlackBerryContact Phone Numbers
Retrieving BlackBerryContact phone numbers and the labels then showing it in a dialog to let user to choose.
BlackBerryContact c;
Find out the number of phone numbers saved under a contact
c.countValues(BlackBerryContact.TEL);
Setup variables to hold the numbers and their labels.
phoneNumbers = new String[phoneCount];
labels = new String[phoneCount];
String label = "";
Go through a loop to get the numbers and find out the label
for(int i = 0; i < phoneCount; i++)
{
//Fetch the phone number
String phoneNumber = c.getString(BlackBerryContact.TEL, i);
//Determine the label for that number
if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_MOBILE)
{
label = "mobile";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_WORK)
{
label = "work";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_HOME)
{
label = "home";
}
//Add the number and label to the array.
phoneNumbers[i] = phoneNumber;
labels[i] = label;
}//end of for loop
Display the number in a Dialog.ask
StringBuffer sb = new StringBuffer();
//If more than one numbers found
if(phoneCount > 1)
{
int choice = Dialog.ask("Which number to use?",labels,0);
if (choice == 0)
{
sb.append(phoneNumbers[0]);
}
else if (choice == 1)
{
sb.append(phoneNumbers[1]);
}
else if (choice == 2)
{
sb.append(phoneNumbers[2]);
}
else if(choice == Dialog.CANCEL)
{
sb.append("CANCEL");
}
}
BlackBerryContact c;
Find out the number of phone numbers saved under a contact
c.countValues(BlackBerryContact.TEL);
Setup variables to hold the numbers and their labels.
phoneNumbers = new String[phoneCount];
labels = new String[phoneCount];
String label = "";
Go through a loop to get the numbers and find out the label
for(int i = 0; i < phoneCount; i++)
{
//Fetch the phone number
String phoneNumber = c.getString(BlackBerryContact.TEL, i);
//Determine the label for that number
if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_MOBILE)
{
label = "mobile";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_WORK)
{
label = "work";
}
else if(c.getAttributes(BlackBerryContact.TEL,i) == BlackBerryContact.ATTR_HOME)
{
label = "home";
}
//Add the number and label to the array.
phoneNumbers[i] = phoneNumber;
labels[i] = label;
}//end of for loop
Display the number in a Dialog.ask
StringBuffer sb = new StringBuffer();
//If more than one numbers found
if(phoneCount > 1)
{
int choice = Dialog.ask("Which number to use?",labels,0);
if (choice == 0)
{
sb.append(phoneNumbers[0]);
}
else if (choice == 1)
{
sb.append(phoneNumbers[1]);
}
else if (choice == 2)
{
sb.append(phoneNumbers[2]);
}
else if(choice == Dialog.CANCEL)
{
sb.append("CANCEL");
}
}
Friday, 3 April 2009
Processes and Port Numbers
Need to find out what process is using a certain port? Use CurrPorts! Download it here. Download the whole zip file and extract it. There would be a number of programs inside. Open up CurrPorts and it would list all the processes using the respective port numbers.
To kill the process:
Now that you know what is the process, open Task Manager(CTRL + ALT + DEL) and search for the process. Select it and press End Process.
:)
I had to use this because there was a port being used and I could not do On-Device Debugging to my Sony Ericsson JP-8 phone. So this might help some of you people out there!
To kill the process:
Now that you know what is the process, open Task Manager(CTRL + ALT + DEL) and search for the process. Select it and press End Process.
:)
I had to use this because there was a port being used and I could not do On-Device Debugging to my Sony Ericsson JP-8 phone. So this might help some of you people out there!
Thursday, 2 April 2009
Minimizing MIDlets in Sony Ericsson
To check if a MIDlet is minimized, the Displayable.isShown() method can be used. It is of course preferable to check for a minimized MIDlet this way:
private boolean isOnBackGround(){
boolean isOnBackGround =(BubbleTalk.getDisplay().getCurrent() == null ||
!BubbleTalk.getDisplay().getCurrent().isShown());
return isOnBackGround;
}
For more information regarding minimizing MIDlets in Sony Ericsson, click here.
private boolean isOnBackGround(){
boolean isOnBackGround =(BubbleTalk.getDisplay().getCurrent() == null ||
!BubbleTalk.getDisplay().getCurrent().isShown());
return isOnBackGround;
}
For more information regarding minimizing MIDlets in Sony Ericsson, click here.
Wednesday, 1 April 2009
pauseApp() never called?
Just for your information...
"On Series 40 Development PLatform 1.0 phones, the pauseApp() method of your MIDlet will never be called, so you can detect whether your application is paused only by using the hideNotify() method of Canvas."
Taken from here
Check whether hideNotify() or isShown() methods will be called if u accept/reject the call. At times it may enter any of these methods.
"On Series 40 Development PLatform 1.0 phones, the pauseApp() method of your MIDlet will never be called, so you can detect whether your application is paused only by using the hideNotify() method of Canvas."
Taken from here
Check whether hideNotify() or isShown() methods will be called if u accept/reject the call. At times it may enter any of these methods.
On Device Debugging in Sony Ericsson
Sony Ericsson provides a very useful tool for us developers which is the On-Device Debugging. What makes it better is that they even have a wiki on this to document the steps on how to do an On-Device Debugging. Below is a useful video to help you out. It is however applicable for Java Platform 8 and above(probably).
For those below Java Platform 8, the steps are very similar to the one shown below. Only difference is that you need to find out the port number and select it in the Connection Proxy to connect the device to the PC.
Please take note that to enable Java Developer Mode(JP-8 Phones)
Click Right * Left Left * Left *
For phones of lower than JP-8, there is no need to enable the Java Developer Mode.
For those below Java Platform 8, the steps are very similar to the one shown below. Only difference is that you need to find out the port number and select it in the Connection Proxy to connect the device to the PC.
Please take note that to enable Java Developer Mode(JP-8 Phones)
Click Right * Left Left * Left *
For phones of lower than JP-8, there is no need to enable the Java Developer Mode.
Subscribe to:
Posts (Atom)