OnActivityResult在xamarin中不起作用

问题描述 投票:0回答:1

im试图用蓝牙连接编写应用程序,当我收到有关打开蓝牙的请求时,我必须选择是或否,当我这样做时,它应该显示像吐司的小消息,但它不显示,我试图进行功能内部烘烤,如果仍然无法正常工作,请帮助

        BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter;

        if (bluetoothAdapter == null)
        {
            Toast.MakeText(Application.Context, "xxx ", ToastLength.Short).Show();
        }

        if (!bluetoothAdapter.IsEnabled)
        {
            Intent wlaczbt = new Intent(BluetoothAdapter.ActionRequestEnable);
            StartActivityForResult(wlaczbt, REQUEST_ENABLE_BT);
            //OnActivityResult(REQUEST_ENABLE_BT, Result.Ok, wlaczbt);
        }
        else
        {
            Toast.MakeText(Application.Context, "xxx ", ToastLength.Short).Show();
        }

OnActivity:

public void OnActivityResult(int requestCode,int resultCode,Intent data)
{
    base.OnActivityResult(requestCode, Result.Ok , data);
    Toast.MakeText(Application.Context, "xx ", ToastLength.Short).Show();
    if (requestCode == REQUEST_ENABLE_BT)
    {
        if(resultCode.Equals(Result.Ok))
        {
            Toast.MakeText(Application.Context, "xx ",ToastLength.Short).Show();
        }
        else
        {
            Toast.MakeText(Application.Context, "xx ", ToastLength.Short).Show();
        }
    }
}
xamarin bluetooth onactivityresult
1个回答
0
投票

我编写了一个有关它正常工作的演示。这是运行GIF。enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.