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
Developer
zahidalinaqvi
Posts: 445
Registered: ‎10-14-2008
My Device: Blackberry Bold 9000

Implement listener in backgound application

hello,

 

how i can implement a PhoneListener in a background application.

 

in the below code i want to implement PhoneListener listener. on every call connect i want to viberate the phone.

 

Code: 

 

WHATS WRONG WITH THIS CODE :

 

/**
* GUILessApplication
*
* A sample application that appears on the ribbon
* but does not have any user interface.
*/


import net.rim.blackberry.api.phone.PhoneListener;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

public final class GUILessApp extends Application  
{
    int flag=0;
     private BackGroundApp backGroundApp;
     public static void main(String[] args)
     {
          GUILessApp theApp = new GUILessApp();
          theApp.enterEventDispatcher();
     }

     public GUILessApp()
     {
          //Creates and starts a new BackGroundApp thread.

          backGroundApp = new BackGroundApp();
          backGroundApp.start();
     }

     //The thread that will run in the background.
     private class BackGroundApp extends Thread implements PhoneListener
     {
         
          boolean stopThread = false;
          public synchronized void stop()
          {
               stopThread = true;
          }

          public void run()
          {
               while (!stopThread)
               {
                   //if(flag == 1)
                     //Alert.startVibrate(75);

                          
                    //You would perform your processing here.
                    //This sample just prints out a line
                    //to the BlackBerry JDE Output Window
                    System.out.println("Application is running");

                    //Sleep for 5 seconds to prevent the
                    //application from running out of control
                    try
                    {
                         sleep(500);
                    }
                    catch (Exception e)
                    {
                         //Exception handling would go here.
                    }
               }
          }

        public void callAdded(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callAnswered(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callConferenceCallEstablished(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callConnected(int arg0) {
            // TODO Auto-generated method stub
            Alert.startVibrate(75);
           
        }

        public void callDirectConnectConnected(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callDirectConnectDisconnected(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callDisconnected(int arg0) {
            // TODO Auto-generated method stub
            Alert.startVibrate(75);
           
        }

        public void callEndedByUser(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callFailed(int arg0, int arg1) {
            // TODO Auto-generated method stub
           
        }

        public void callHeld(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callIncoming(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callInitiated(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callRemoved(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callResumed(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void callWaiting(int arg0) {
            // TODO Auto-generated method stub
           
        }

        public void conferenceCallDisconnected(int arg0) {
            // TODO Auto-generated method stub
           
        }

     }
     //Stop the thread on exit.
     protected void onExit()
     {
          backGroundApp.stop();
     }


}

   
 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks & Regards
Zahid Naqvi | Senior Software Engineer
Please use plain text.
Administrator
MSohm
Posts: 14,569
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Implement listener in backgound application

You don't need a background thread.  It isn't doing anything in this case.  Instead, register the PhoneListener and place the code to vibrate within the methods of the PhoneListener interface.  You can find an example here:  http://na.blackberry.com/eng/devjournals/resources/journals/jan_2005/api_spotlight_phone.jsp
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.