سؤال

أحاول الحصول على قائمة بجميع الخلايا المتاحة التي يمكن للجهاز العثور عليها.ولكن أنا عالقة ، كما سيلينفو بلدي هو دائما فارغة وأنا لا الرقم لماذا.يمكن للشخص أن تعطيني تلميحا?هناك عدد قليل جدا من المعلومات على أونسيلينفوشانجيد () في جوجل.

النشاط الرئيسي:

 CellListener cellListener = new CellListener(this);
 cellListener.start();

سيلليستينر:

public class CellListener extends PhoneStateListener {

private static final String TAG = "CellListener";
private TelephonyManager telephonyManager = null;
private PhoneStateListener listener = null;
private String newCell = null;  
private int events = PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_CELL_INFO;
private Context context = null;

public CellListener(Context context) {
    this.context = context;
}

public void start() {

    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    CellLocation.requestLocationUpdate();

    telephonyManager.listen(this, events);
}

@Override
public void onCellInfoChanged(List<CellInfo> cellInfo) {
    Log.i("CellListener","onCellInfoChanged(List<CellInfo> cellInfo) ");
    super.onCellInfoChanged(cellInfo);

     if(cellInfo == null) return;     // this always null here

     for (CellInfo c : cellInfo) {          
        Log.i("CellListener"," c = "+c);
    }       
 }

 @Override
    public void onCellLocationChanged(CellLocation location) {
        if (!(location instanceof GsmCellLocation)) {
            return;
        }
        GsmCellLocation gsmCell = (GsmCellLocation) location;
        String operator = telephonyManager.getNetworkOperator();
        if (operator == null || operator.length() < 4) {
            return;
        }
        newCell = operator.substring(0, 3) + ':' + operator.substring(3) + ':'
                + gsmCell.getLac() + ':' + gsmCell.getCid();

        Log.i(TAG,"newCell = "+newCell);     
    }
}

لوغكات:

11-18 14:50:23.806: I/CellListener(4953): newCell = 262:02:4311:99031735
11-18 14:50:23.814: I/CellListener(4953): onCellInfoChanged(List<CellInfo> cellInfo) 

كما ترون كل من الأحداث (أونسيلينفوشانجيد و أونسيللوكاتيونشانجيد) الحصول على تشغيل مرة واحدة وهذا الأخير هو العودة بشكل صحيح الخلية الحالية الجهاز يستخدم.

هل كانت مفيدة؟

المحلول

السبب الحقيقي الذي يتم استدعاؤه مرة واحدة فقط ومع نول كوسيطة هو ما يلي:يبدو أن هناك إعداد تحديد معدل في مكان افتراضيا ، كما يمكن ملاحظته في" اختبار " التطبيق ، والتي يمكن الوصول إليها عن طريق الاتصال *#*#INFO#*#* (أي. *#*#4636#*#*).

في تطبيق الاختبار ، اختر "معلومات الهاتف" وانتقل لأسفل إلى الزر CELLINFOLISTRATE xxxx, ، في قضيتك يفترض CELLINFOLISTRATE 2147483647.كما 2147483647 == MAX_INT, ، ربما يعني هذا عدم وجود مكالمات على الإطلاق

بالنسبة لي (الأسهم الروبوت 6.0 ، نيكزس 6) ، وهناك خيار بين MAX_INT (مكالمة واحدة مع لاغية), 0 و 1000.

لست متأكدا بنسبة 100 ٪ مما تعنيه هذه القيم ، ولكن من المفترض أن 0 يرمز إلى المكالمات الفورية (وبالتالي كثيرة جدا) ، و 1000 لشيء مثل ثانية على الأقل بين المكالمات.نضع في اعتبارنا على الرغم من هذا هو مجرد تكهنات.

سأقوم بتحرير هذه الإجابة كلما اكتشفت المزيد ، على سبيل المثال من خلال النظر في تنفيذ تطبيق الاختبار المذكور.

نصائح أخرى

@bofredo: It is returning null because you haven't defined CellInfo yet.

Can't see from your question if you're using CDMA, GSM, or LTE. From memory, CDMA doesn't seem to return anything, but GSM (CellInfoGsm) and LTE (CellInfoLte) do. So doing something like for example:

CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;

will return an instance of CellInfoGsm or CellInfoLte which will then allow you to retrieve more information about a cell like:

CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();  

or

CellSignalStrengthGsm cellSignalStrengthGsm = cellInfoGsm.getCellSignalStrength();
CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength();

Then use cellIdentityGsm, cellIdentityLte, cellSignalStrengthGsm and cellSignalStrengthLte to do what you want in onCellInfoChanged.

In addition to @bimmlerd answer. If you are updating the Phone Information via dialing *#*#INFO#*#* (i.e. *#*#4636#*#*). There are chances that the hidden menu doesn't appear. In that case, use default dialer if you are using some 3rd party call management application (Worked for me as it was not showing any hidden menu for phone information).

https://www.reddit.com/r/GooglePixel/comments/6xc40q/4636_service_menu_not_available_in_oreo/

Note: The following picture will help you with the latest Android OS. Just update the mobile info refresh rate in phone information 1/2 option (I hope multiple phone information because of multiple sim cards)

Hidden Menu enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top