user1025050
user1025050

Reputation:

android:cellid and lac not working

I am making an app in which i have to get the lac and cell id . I am using

private PhoneStateIntentReceiver mPhoneStateReceiver;
ServiceState state = mPhoneStateReceiver.getServiceState();

 int cid = state.getCid();
 int lac = state.getLac();

and its giving error that PhoneStateIntentReceiver cannnot resolved to type and getcellid and getlac is also giving errorthat getcellid is undefined for ServiceState

Any help will be appreciated.

Upvotes: 0

Views: 1264

Answers (1)

Sujit
Sujit

Reputation: 10632

use this to get cid and Lac

 final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
    final GsmCellLocation location = (GsmCellLocation) telephony.getCellLocation();
    if (location != null) {
        msg.setText("LAC: " + location.getLac() + " CID: " + location.getCid());
    }
}

with permission

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Upvotes: 1

Related Questions