【问题标题】:how to send value from android-project to share-project?如何将价值从 android-project 发送到 share-project?
【发布时间】:2021-06-12 23:40:52
【问题描述】:

如何将verificationIdSendOtpCodeAsync()发送到SendCode_Button_Clicked()

分享项目代码

 IAuth auth; 
 auth = DependencyService.Get<IAuth>();
private async void SendCode_Button_Clicked(object sender, EventArgs e)
{
       bool result = await auth.SendOtpCodeAsync(PhonenumberEntry.Text);
}

android项目代码

[assembly: Dependency(typeof(AuthDriod))]
namespace TestApp_MiniApps.Droid
{
    public class AuthDriod : PhoneAuthProvider.OnVerificationStateChangedCallbacks, IAuth
    {
        private TaskCompletionSource<bool> _phoneAuthTcs;

        public Task<bool> SendOtpCodeAsync(string phonenumber)
        {
            _phoneAuthTcs = new TaskCompletionSource<bool>();

            Java.Lang.Long num = (Java.Lang.Long)60;
            PhoneAuthOptions options =
                PhoneAuthOptions.NewBuilder(FirebaseAuth.Instance)
                .SetPhoneNumber(phonenumber)       // Phone number to verify
                .SetTimeout(num, TimeUnit.Seconds) // Timeout and unit
                .SetActivity(Platform.CurrentActivity)                 // Activity (for callback binding)
                .SetCallbacks(this)          // OnVerificationStateChangedCallbacks
                .Build();
            PhoneAuthProvider.VerifyPhoneNumber(options);

            return _phoneAuthTcs.Task;
        }

        public override void OnVerificationCompleted(PhoneAuthCredential credential)
        {      
        }

        public override void OnVerificationFailed(FirebaseException exception)
        {
            _phoneAuthTcs?.TrySetResult(false);
        }

        public override void OnCodeSent(string verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken)
        {
            base.OnCodeSent(verificationId, forceResendingToken);
            _phoneAuthTcs?.TrySetResult(true);

        }
    }//end of class
}

分享项目界面

namespace TestApp_MiniApps.Views.Xamarin.FireBase
{
    public interface IAuth
    {
        Task<bool> SendOtpCodeAsync(string phonenumber);
    }//end of class
}

【问题讨论】:

  • 堆栈跟踪应该显示导致异常的行号
  • 感谢您回来。是的,错误是因为我将字符串从share-project 传递到android-project。我也尝试转换为StringToString
  • 我怀疑这就是原因。你正在做的唯一明显的演员是Java.Lang.Long。如果您按照我的建议查看堆栈跟踪,它将确认这一点
  • 问题是什么?当你尝试它时会发生什么?这不编译吗?或者你在运行时遇到异常?哪一行代码失败了?
  • 问题我如何发送价值。我在谷歌上看,但很难找到一些类似的。你知道我怎么发送它,或者我可以看看你可能有的一些链接吗?

标签: c# android xamarin xamarin.forms xamarin.android


【解决方案1】:

要总结 Leo 在 cmets 中添加的内容,您可以检查方法调用返回的内容。

bool 更改为您自己的班级。出于此答案的目的,我将其称为OtpResult

// The new class definition:
public class OtpResult
{
    public bool Success { get; set; }

    // Define whatever you like here
    public string StringValue { get; set; }
}


public interface IAuth
{
    Task<OtpResult> SendOtpCodeAsync(string phonenumber);
}

【讨论】:

  • 我正在查看 xamarin 文档。他们有 secure storage clipboardperformance。我认为如果我使用它们在页面之间传递值会很简单。这是一个坏主意吗?告诉我
  • @ikhlasahmed 这可能是这里另一个问题的主题,但我不建议使用这些选项。试试docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/…
猜你喜欢
  • 2013-02-10
  • 2015-01-14
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 2014-07-27
相关资源
最近更新 更多