question

DustOfRust-9188 avatar image
0 Votes"
DustOfRust-9188 asked RobCaplan edited

Xamarin TelephonyManager requestCellInfoUpdate how run?

How to run this method?

 public void requestCellInfoUpdate (Executor executor, 
                 TelephonyManager.CellInfoCallback callback)

My code:

     TelephonyManager tm = (TelephonyManager)this.GetSystemService(TelephonyService);
     tm.RequestCellInfoUpdate(MainExecutor, new TelephonyManager.CellInfoCallback());


new TelephonyManager.CellInfoCallback()) - this is a problem with that, but I don't know. How to start it and what to enter? From what I can see it's an abstract class?

I can't find anything in the Xamarin documentation. And in the Adnroid documentation, I found that it is necessary to call it from API29 to refresh the information.



Apps targeting Android Q or higher will no longer trigger a refresh of the cached CellInfo by invoking this API. Instead, those apps will receive the latest cached results, which may not be current. Apps targeting Android Q or higher that wish to request updated CellInfo should call requestCellInfoUpdate(); however, in all cases, updates will be rate-limited and are not guaranteed. To determine the recency of CellInfo data, callers should check CellInfo#getTimeStamp().



https://developer.android.com/reference/android/telephony/TelephonyManager#requestCellInfoUpdate(java.util.concurrent.Executor,%20android.telephony.TelephonyManager.CellInfoCallback)





dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

And how to get data from OnCellInfo to other class or show send to textMessage?


 public override void OnCellInfo(IList<CellInfo> cellInfo)
             {
                 foreach (var item in cellInfo)
                 {
                     //item.CellIdentity.
                     textMessage.Text += "\n\n" + item.GetType() + "\n";  //- error CS0120 An object reference is required for the non-static field, method, or property 'MainActivity.textMessage'
    
                 }
             }
0 Votes 0 ·

1 Answer

ColeXia-MSFT avatar image
1 Vote"
ColeXia-MSFT answered ColeXia-MSFT edited

Hello,

Welcome to Microsoft Q&A!

We can create a new class inherit from the abstract class TelephonyManager.CellInfoCallback , and override the method OnCellInfo inside the new class .

Check the code below

public class MyCallBack : TelephonyManager.CellInfoCallback
    {
        public override void OnCellInfo(IList<CellInfo> cellInfo)
        {
            //here get cell info
        }
    }

 TelephonyManager tm = (TelephonyManager)this.GetSystemService(TelephonyService);
 tm.RequestCellInfoUpdate(MainExecutor, new MyCallBack());


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

And how to pass data from OnCellInfo to other class or show send to textMessage?


 public override void OnCellInfo(IList<CellInfo> cellInfo)
             {
                 foreach (var item in cellInfo)
                 {
                     //item.CellIdentity.
                     textMessage.Text += "\n\n" + item.GetType() + "\n";  //- error CS0120 An object reference is required for the non-static field, method, or property 'MainActivity.textMessage'
    
                 }
             }



0 Votes 0 ·

You could use MessagingCenter to send the data to the other class .


Send

public override void OnCellInfo(IList<CellInfo> cellInfo)
        {
             foreach (var item in cellInfo)
                 {
                     //item.CellIdentity.
                     string data;
                     data += "\n\n" + item.GetType() + "\n";  

                     MessagingCenter.Send<object, string>(this, "Hi", data );
                 }
        }


Subscribe in other class

MessagingCenter.Subscribe<object, string>(this, "Hi", (sender, arg) =>
{
    textMessage.Text = arg;
});


0 Votes 0 ·

The question is why OnCellInfo doesn't return the requested items from CellInfoNr?

The terminal is 5G, in the NSA architecture, connected to a 5G cell.
OnCellInfo GetType returns CellInfoLte, CellInfoWCDMA to me, but when I connect it to a 5G cell, I don't know why I don't have CellInfoNr.

How to poll the TelephonyManager correctly to get CellInfoNr information?

This is Android 10.
I checked with other applications from the google store and I can see that my phone displays these CellInfoNr parameters.

I'm using 5G NSA and maybe that's why OnCellInfo doesn't return CellInfoNr?
But if so how do you get it?

0 Votes 0 ·
Show more comments