为什么Xamarin类由于保护级别而无法访问?

oprakyz7  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(144)

我正在尝试访问Xamarin表单中的电话管理器类。我阅读了Xamarin中需要使用的constructor
虽然我对构造函数所需的类型和推理仍有一点困惑,但我将几个我认为应该起作用的构造函数参数放在一起。
由于其保护级别,无法访问电话管理器(IntPtr,JNIHandleOwnership)
怎么会这样呢?据我所知,这个安卓类的C#版本的保护级别是无法控制的。

using Android.Telephony;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CellularSignal
{
    public class MainActivityViewModel
    {
        public double getRSSI()
        {
            IntPtr ptr = IntPtr.Zero;
            // **Intellisense error on line below**
            var t = new TelephonyManager(ptr, JniHandleOwnership.DoNotTransfer);
            return 0;

        }
    }
}
vngu2lb8

vngu2lb81#

像这样的东西应该管用

TelephonyManager tpMgr = (TelephonyManager)mAppContext.GetSystemService(Context.TelephonyService);

其中,mAppContext是您在应用中使用的当前Activity,如果您位于其中一个Fragments中,则可以从Activity属性获取Activity
祝你好运

相关问题