How to find user location using cell tower in J2ME?

java, java-me, mobile

Solution

This Cell info is broadcasted as CBS (Cell Broadcast Service) message by the cell towers and received by all the GSM phones connected to this tower on certain predefined Channel (generally 050) by most of the service providers. Thus our Java ME application can listen to this CBS Channel using Push Registry and capture this information.

Follow the steps,

Import libraries

import javax.wireless.messaging.*;
import javax.microedition.io.PushRegistry;

Register your Midlet for Listening to CBS port 50 and setup a Message Listener

public void setupListening()
{        
    try{
    PushRegistry.registerConnection("cbs://:50",this.getClass().getName(),"*");
    }catch(Exception e){}
    String[] connList;
    connList = PushRegistry.listConnections(true);
if((connList == null) || (connList.length == 0))
{
  // You can exit the app, if you want
}
else 
    { 
    try{
    msgconn = (MessageConnection)Connector.open("cbs://:50");
        msgconn.setMessageListener(this);
    } catch( IOException e){ e.printStackTrace();}
     }
}

To Retrieve the CBS message payload.

public void notifyIncomingMessage(MessageConnection conn)
{
  try{
        txtmsg =(TextMessage)msgconn.receive();
     }catch(Exception e){System.out.println(e);}
     from = txtmsg.getAddress());
     Msg = txtmsg.getPayloadText();
    // Display from & Msg            
}

Problem

I just want to find the location name using cell tower in j2me. Also how to redirect the incoming call to our own application from where the caller number is shown to user like the normal calling information? [as of now when some one calls someone the mobile number is shown,] I want to show the receiver of the call the location of the caller with his/her mobile number.

Original source