Trying to use DependencyService to start Card.IO component, the problem is that, the event OnActivityResult only fires on the MainActivity, am I doing something wrong or it's a Xamarin Forms restriction?
Here is the code:
public class CardScanner : FormsApplicationActivity, PedirComida.Controls.ICardScanner
{
TaskCompletionSource<string> aRetornar;
public async Task<string> ScanAsync()
{
aRetornar = new TaskCompletionSource<string>();
var intent = new Intent(Forms.Context, typeof(CardIOActivity));
intent.PutExtra(CardIOActivity.ExtraRequireExpiry, true);
intent.PutExtra(CardIOActivity.ExtraRequireCvv, true);
intent.PutExtra(CardIOActivity.ExtraRequirePostalCode, false);
intent.PutExtra(CardIOActivity.ExtraUseCardioLogo, true);
((Activity)Forms.Context).StartActivityForResult(intent, 101);
return await aRetornar.Task;
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (data != null)
{
var card = data.GetParcelableExtra(CardIOActivity.ExtraScanResult).JavaCast<CreditCard>();
aRetornar.SetResult(card.FormattedCardNumber);
}
}
}