BroadcastReciever中的Xamarin Android访问变量

时间:2018-12-15 15:47:42

标签: c# xamarin.android broadcastreceiver android-broadcast

我有一个broadcastReciever来检查传入的意图。传入的intent包含一个BluetoothDevice。在BroadcastReceiver中,我检查天气是否正确BluetoothDevice。如果是,我想将设备的名称和MAC地址存储在变量中。

我的问题:我只能访问在我的BroadcastReciever中声明为variable的{​​{1}}。如何访问const内部的变量?

BoradcastReceiver

...

namespace firstTry3
{
[Activity(Label = "@string/app_name")]
public class bluetoothConnectionActivity : AppCompatActivity
{
    BluetoothAdapter mBluetoothAdapter;
    Button buttonBluetoothOn;
    Button buttonConnect;
    Button buttonDissconnect;
    const string deviceName = "HC-05";                  //must be changed when bluetooth Device gets new name
    string deviceMAC = "";
    const string tag = "blueApp";
    btdeviceFoundBroadcastReceiver mBtBroadcastReciever;

我无法访问deviceMAC,但出现以下错误: “非静态字段,方法或属性bluetoothConnectionActivity.deviceMethod需要对象引用”

0 个答案:

没有答案