I'm new to android, and I work on a project that goes to collect all cells information that observed by phone. I have used TelephonyManager.getAllCellInfo()
method, but it always returns null
.
My Code ::
public class NetworkCoverageActivity extends AppCompatActivity {
private String str;
private TextView TV;
private Button getCellsInfoBtn;
private TelephonyManager TM;
private List<CellInfo> cellInfoList;
private PhoneStateListener PSL;
private int event;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_network_coverage);
TV = (TextView)findViewById(R.id.iv);
getCellsInfoBtn = (Button)findViewById(R.id.getCellsInfoBtn);
TM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
PSL = new PhoneStateListener();
event = PSL.LISTEN_CELL_INFO | PSL.LISTEN_CELL_LOCATION;
getCellsInfoBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
TM.listen(PSL, event);
cellInfoList = TM.getAllCellInfo();
if(cellInfoList != null)
TV.append("cellInfoList = null");
else{
...
}
}
});
}
I'm working on android 4.4.2 level 17 and set min API level to 17. and I try to collect information from GSM network.
Also, I added the following permission to AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>