Getallcellinfo Returns Null in Android 4.2.1

Android getAllCellInfo() returns null

I have got the solution of my question. that's replaced getAllCellInfo() function by getNeighboringCellInfo() function, although I am running with android level 17 that should be support getAllCellInfo() function and getNeighboringCellInfo() function should be no longer supported.
Anyway, the following is the solution.

package ayad.bslm.com.networkcoverage;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

public class NetworkCoverageActivity extends AppCompatActivity {

private TextView TV;
private TelephonyManager TM;
private List<NeighboringCellInfo> neighboringCellInfoList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_network_coverage);

TV = (TextView)findViewById(R.id.iv);
Button getCellsInfoBtn = (Button)findViewById(R.id.getCellsInfoBtn);
TM = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

getCellsInfoBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
neighboringCellInfoList = TM.getNeighboringCellInfo();

if(neighboringCellInfoList == null)
TV.setText("neighboringCellInfoList == null\n");
else
TV.setText("There are " + neighboringCellInfoList.size() + " Cells\n");
}
});
}
}

getAllCellInfo() returns empty list in honor 9n

If the user has disabled device location on a device running Android 9, the following methods don't provide results:

getAllCellInfo()
listen()
getCellLocation()
getNeighboringCellInfo()


Related Topics



Leave a reply



Submit