我的应用正在使用startActivityForResult
从另一个程序包开始活动。在重新创建启动活动时,我发现了问题,并发现在启动的活动返回后,在这种情况下未调用onActivityResult
。 (如果我不触发活动重新创建,则可以正确调用。)
这些是我执行的步骤:
startActivityForResult
我发现,如果我为Permission.UseFingerprint调用RequestPermissions
,即使活动恢复后,我也会得到OnActivityResult回调。我不知道为什么。有人可以解释这种行为吗?
可能与ykDroid有关吗?有关其源代码,请参见https://github.com/pp3345/ykDroid。
以下是我用于测试的内容(Xamarin Android):
[Activity(Label = "@string/app_name", Theme = "@style/MyTheme")]
public class DatabaseSettingsActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.yubichall_test);
FindViewById<Button>(Resource.Id.btn_yubichall).Click += (sender, args) =>
{
byte[] challenge64 = new byte[64];
for (int i = 0; i < 64; i++)
{
challenge64[i] = (byte) i;
}
var chalIntent = TryGetYubichallengeIntentOrPrompt(challenge64, true);
StartActivityForResult(chalIntent, 123);
};
//Uncomment this and it will work
/* if ((int)Build.VERSION.SdkInt >= 23)
RequestPermissions(new[] { Manifest.Permission.UseFingerprint }, 99);*/
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Kp2aLog.Log("OnActivityResult: " + requestCode);
if (resultCode == Result.Ok)
{
byte[] challengeResponse = data.GetByteArrayExtra("response");
if ((challengeResponse != null) && (challengeResponse.Length > 0))
{
FindViewById<TextView>(Resource.Id.text_result).Text =
MemUtil.ByteArrayToHexString(challengeResponse);
}
}
}
public Intent TryGetYubichallengeIntentOrPrompt(byte[] challenge, bool promptToInstall)
{
Intent chalIntent = new Intent("net.pp3345.ykdroid.intent.action.CHALLENGE_RESPONSE");
chalIntent.PutExtra("challenge", challenge);
IList<ResolveInfo> activities = PackageManager.QueryIntentActivities(chalIntent, 0);
bool isIntentSafe = activities.Count > 0;
if (isIntentSafe)
{
return chalIntent;
}
if (promptToInstall)
{
//please install https://play.google.com/store/apps/details?id=net.pp3345.ykdroid&hl=en
}
return null;
}
}
布局yubicall_test是
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_yubichall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yubi challenge"
/>
<TextView
android:id="@+id/text_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>