Show me the code! – By Davanum Srinivas

November 29, 2007

Android – Access Cell Phone details (Cell-Id, LAC, Signal Strength)

Filed under: Uncategorized — Davanum Srinivas @ 9:57 am

Here is the screen shot

001

Next Step(s)!


Need to figure out how to use cell-id/lac information to get a lat/long for the phone location! Please drop me a note or add comments here if you have an idea on how to do it. Thanks.

Source

package org.apache;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.PhoneStateIntentReceiver;
import android.telephony.ServiceState;
import android.util.Log;
import android.widget.EditText;

public class LocateMe extends Activity {
    private PhoneStateIntentReceiver mPhoneStateReceiver;
    private EditText mEditLac;
    private EditText mEditCid;
    private EditText mEditSignal;

    private static final int MY_NOTIFICATION_ID = 0x100;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        mPhoneStateReceiver = new PhoneStateIntentReceiver(this, new ServiceStateHandler());
        mPhoneStateReceiver.notifyServiceState(MY_NOTIFICATION_ID);
        mPhoneStateReceiver.notifyPhoneCallState(MY_NOTIFICATION_ID);
        mPhoneStateReceiver.notifySignalStrength(MY_NOTIFICATION_ID);
        mPhoneStateReceiver.registerIntent();

        mEditLac = (EditText) findViewById(R.id.lac);
        mEditCid = (EditText) findViewById(R.id.cell_id);
        mEditSignal = (EditText) findViewById(R.id.signal_strength);
    }

    private class ServiceStateHandler extends Handler {
        public void handleMessage(Message msg) {
            Log.i("LocateMe", "In handleMessage : " + msg.what);
            switch (msg.what) {
                case MY_NOTIFICATION_ID:
                    ServiceState state = mPhoneStateReceiver.getServiceState();
                    int cid = state.getCid();
                    int lac = state.getLac();
                    int signal = mPhoneStateReceiver.getSignalStrength();
                    mEditCid.setText("" + cid);
                    mEditLac.setText("" + lac);
                    mEditSignal.setText("" + signal);
                    break;
            }
        }
    }
}

Download the sources and Application – LocateMe.zip

UPDATE: Nov 30, 12:37 EST – Version 2.0 is here

16 Comments »

  1. Have a look at this thread here:

    http://discussion.forum.nokia.com/forum/showthread.php?s=&threadid=19693

    It’s a Symbian forum, but it goes into the whole topic of CellID -> Lat/Lng conversion

    Hope it helps…. I’m not sure it will (as it’s a bit long and I’m only on the 1st page so far)

    Comment by bloid — November 29, 2007 @ 10:06 am

  2. This may be of use as well… It seems to use the yahoo flickr location service:

    http://www.openwiki.com/ow.asp?CellIDToLocation

    Comment by bloid — November 29, 2007 @ 10:14 am

  3. Here is what you are looking for:
    http://www.gnucitizen.org/blog/geo-tracking-mobile-phones

    Note that you also need the MCC and MNC.

    Comment by Nicolas — November 30, 2007 @ 7:52 am

  4. […] Android – Poor man’s “My Location” (Show current cell location) Many Thanks to Nicholas and bloid for comments on my previous blog post. Here’s an update with some commentary […]

    Pingback by Android - Poor man’s “My Location” (Show current cell location) « Show me the code! — November 30, 2007 @ 12:28 pm

  5. Android Location will be a revolutionary social mapping service to change the way people use mobile phones to keep in touch with their friends. It will facilitates real-world interaction between friends and puts an end to frustrating missed connections.
    Using location-based technologies, Android Location lets you know where your friends are by automatically updating maps on your mobile handset. Android Location even lets you send messages to nearby friends or receive automatic alerts when they’re nearby so that you never miss an opportunity to meet. Android Location also lets you journal your life so that your friends can see what you’re up to. With Android Location, mobile subscribers put themselves on the map.
    Features
    + Know where you are without having a GPS Connect with friends and get alerted where they are nearby
    + Explore places and events recommended by friends Recommend new places
    + Search for stuff to buy in nearby stores It will run on any Cell Phone Provider
    + It will run on any Phone (Blackberry, Android, Symbian, Windows Mobile)
    + It will be FREE

    The application is being written in Android and J2ME and there are several people in the project with great programming knowledge, we are in an early stage of the project but we already know how to build the application, it’s only a matter of time to have the application up and running.

    We are seeking for people that would like to join the project to help us build it faster.

    http://www.androidlocation.com/

    Comment by Andres Rormoser — February 1, 2008 @ 3:44 pm

  6. hi
    Im not expert in Java and i want to use this code to get cellid (bts gprs) by any phone.
    i think that my probleme is not great :
    when i write this code an error like : android.app.Activity dont existe
    i want just to know integrate this api to my aps
    sorry for english errors

    Comment by tunisianway@hotmail.fr — March 15, 2008 @ 6:31 am

  7. Would love to do this sort of thing but havnt a clue where to start. I’m glad the integration would be universal with all phone operating systems, that would be key.

    Good luck with all future developments, bookmarked the site 🙂

    Comment by Andy James — April 12, 2008 @ 7:32 pm

  8. You plan too much. Cut down to size and concentrate on it.

    Comment by loty — October 10, 2008 @ 1:26 pm

  9. in the new Android SDK “beta release”

    the method
    int signal = mPhoneStateReceiver.getSignalStrength();

    don’t exists , it there is new way of get the signal strength?

    Comment by ahmdalitaha — November 7, 2008 @ 11:10 am

  10. i am trying to find city location using android api for my app, i tried to download the LocateMe.Zip file, but link is not working, please give me the correct link, would be really helpful

    Comment by android_dev — November 20, 2009 @ 2:00 pm

  11. Why doesn’t it recognize the import android.telephony.PhoneStateIntentReceiver;

    Does it require something. I’m using android 2.1 if it helps

    Comment by wh — May 4, 2010 @ 2:36 pm

  12. Thanks for the great article, I looked here often:)

    Comment by Katal Og — December 26, 2010 @ 4:13 am

  13. Also what?

    Comment by LamuzNick — October 10, 2011 @ 2:03 pm

  14. Please let me know if you’re looking for a article author for your blog. You have some really good posts and I think I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some content for your
    blog in exchange for a link back to mine. Please shoot me an
    email if interested. Kudos!

    Comment by l — April 24, 2013 @ 6:44 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.