gpt4 book ai didi

Android PlacePicker 不返回选择的地址

转载 作者:太空狗 更新时间:2023-10-29 16:26:21 26 4
gpt4 key购买 nike

我在我的 Android 应用程序中使用 Google PlacePicker。我可以用它来选择地址。但是,一旦选择了地址,它就不会返回到调用者 Activity 。相反,我必须按下后退按钮!

这是我初始化 PlacePicker 的方式:

/**
* Add New Address
*/
mNewButton.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try
{
startActivityForResult(builder.build(AddressPickerActivity.this), ADDRESS_CODE);
}
catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e)
{
int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(AddressPickerActivity.this);
GoogleApiAvailability.getInstance().getErrorDialog(AddressPickerActivity.this, status, 100).show();
}
return false;
}
});

这就是我听取结果的方式:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == ADDRESS_CODE)
{
if (resultCode == RESULT_OK)
{
Log.d(TAG, "Google PlacePicker finished");
// Do Stuff then finish current activity too
AddressPickerActivity.this.setResult(RESULT_OK);
AddressPickerActivity.this.finish();
}
}
}

问题是:我没有收到日志消息“Google PlacePicker finished”,除非我按下地点选择器上的后退按钮!之后一切照常进行,我想要执行的操作也能正常工作(这意味着地址已被正确选择)

有个类似的问题here评论表明调用者 Activity 可能在 list 中有 android:noHistory="true"。但是我查了一下,不是。这是我的 list 中的相应 fragment :

<activity
android:name=".AddressPickerActivity"
android:theme="@style/AppThemeNoActionBar" />

这可能是什么原因造成的?

编辑1:

我还尝试将 android:noHistory="false" 显式添加到 list 中。没有变化。

最佳答案

您可以使用 OnClickListener 或尝试为 startActivityForResult 添加 if 条件 MotionEvent.ACTION_UP 因为碰巧 PlacePicker 打开了两次。

mNewButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_UP){
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(AddressPickerActivity.this), ADDRESS_CODE);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(AddressPickerActivity.this);
GoogleApiAvailability.getInstance().getErrorDialog(AddressPickerActivity.this, status, 100).show();
}
}
return false;
}
});

关于Android PlacePicker 不返回选择的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51145927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com