Android – Google PlacePicker在启动后立即关闭

我正在开发一个Android应用程序,并在应用程序中查看Google Places的某些功能。 Google最近发布了PlacePicker功能,这是我正在使用的。我遵循Google指南和“T”快速入门指南。这个功能在三个小时之前是非常令人惊奇的,现在当我去测试它的时候,它会启动,然后立即关闭,而不会在堆栈跟踪中抛出错误。这是我如何使用代码:

这是一个片段。

// The Location Selection from Google Place Picker
where.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        try {
            launchPlace();
        } catch (GooglePlayServicesNotAvailableException |  GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        }
    }
});

这是在片段onCreateView。

方法launchPlace()定义如下。

// Start Google Place Picker Code **************************************************************
public void launchPlace() throws GooglePlayServicesNotAvailableException,
        GooglePlayServicesRepairableException {
    PLACE_PICKER_REQUEST = 1;
    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

    Context context = getActivity().getApplicationContext();
    startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    String badLocation = "That location is not valid for this app, please select a valid location";

    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            place = PlacePicker.getPlace(data, getActivity().getApplicationContext());
            if (place.getPlaceTypes().contains(34)) {
                if (place.getPlaceTypes().contains(9) || place.getPlaceTypes().contains(15) ||
                        place.getPlaceTypes().contains(38) ||
                        place.getPlaceTypes().contains(67) ||
                        place.getPlaceTypes().contains(79)) {
                    where.setText(place.getName());
                    loc = true;
                } else {
                    Toast.makeText(getActivity().getApplicationContext(),
                            badLocation, Toast.LENGTH_LONG).show();
                    try {
                        launchPlace();
                    } catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

这段代码以前工作(3小时前),现在没有。这是LogCat所说的:(Android Studio)

04-21 15:48:02.320    5045-5045/com.siliconmindtech.trofi D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-21 15:48:02.680    5045-5124/com.siliconmindtech.trofi D/OpenGLRenderer﹕ endAllStagingAnimators on 0xa1a55600 (InsetDrawable) with handle 0xa185dff0
04-21 15:48:05.000    5045-5121/com.siliconmindtech.trofi I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
04-21 15:48:05.060    5045-5045/com.siliconmindtech.trofi I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@215c768a time:9757022

如果有人知道有助于这一点令人惊奇的方式,我知道Google PlacePicker是新的,但我是一个新手Android开发人员,觉得有人比我有更好的理解。任何和所有的帮助将不胜感激。如果需要更多信息,请告诉我们。我们使用GitHub,所以我已经恢复一下,当它一旦工作,但没有改变,它仍然关闭(选择器,而不是应用程序)。我已经在开发者控制台中启用Google Places API和Google Places API for Android,也没有帮助。它进入“更新您的位置”屏幕,然后停止。

编辑:这是整个LogCat,从发布(在三星Galaxy S5)到PlacePicker开始(在该操作之前的一个导航),然后关闭并返回到应用程序。这是你的意思吗

04-21 16:56:26.740  27318-27318/com.siliconmindtech.trofi D/ResourcesManager﹕ creating new AssetManager and set to /data/app/com.siliconmindtech.trofi-1/base.apk
04-21 16:56:26.910  27318-27318/com.siliconmindtech.trofi D/AbsListView﹕ Get MotionRecognitionManager
04-21 16:56:26.910  27318-27340/com.siliconmindtech.trofi I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
04-21 16:56:26.910  27318-27340/com.siliconmindtech.trofi I/System.out﹕ (HTTPLog)-Static: isShipBuild true
04-21 16:56:26.910  27318-27340/com.siliconmindtech.trofi I/System.out﹕ (HTTPLog)-Thread-13137-1066627414: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
04-21 16:56:26.910  27318-27340/com.siliconmindtech.trofi I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
04-21 16:56:26.910  27318-27318/com.siliconmindtech.trofi D/AbsListView﹕ Get MotionRecognitionManager
04-21 16:56:26.940  27318-27318/com.siliconmindtech.trofi D/Activity﹕ performCreate Call secproduct feature valuefalse
04-21 16:56:26.940  27318-27318/com.siliconmindtech.trofi D/Activity﹕ performCreate Call debug elastic valuetrue
04-21 16:56:26.950  27318-27318/com.siliconmindtech.trofi D/AbsListView﹕ Get MotionRecognitionManager
04-21 16:56:26.970  27318-27350/com.siliconmindtech.trofi D/OpenGLRenderer﹕ Render dirty regions requested: true
04-21 16:56:27.030  27318-27350/com.siliconmindtech.trofi I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.25.01.03
    Build Date: 10/28/14 Tue
    Local Branch: LA.BF.1.1_RB1_20141028_021_patches2
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
04-21 16:56:27.030  27318-27350/com.siliconmindtech.trofi I/OpenGLRenderer﹕ Initialized EGL, version 1.4
04-21 16:56:27.050  27318-27350/com.siliconmindtech.trofi I/OpenGLRenderer﹕ HWUI protection enabled for context ,  &this =0xa23090d8 ,&mEglDisplay = 1 , &mEglConfig = 8
04-21 16:56:27.050  27318-27350/com.siliconmindtech.trofi D/OpenGLRenderer﹕ Enabling debug mode 0
04-21 16:56:27.050  27318-27340/com.siliconmindtech.trofi I/System.out﹕ KnoxVpnUidStorageknoxVpnSupported API value returned is false
04-21 16:56:27.240  27318-27350/com.siliconmindtech.trofi V/RenderScript﹕ Application requested CPU execution
04-21 16:56:27.260  27318-27350/com.siliconmindtech.trofi V/RenderScript﹕ 0xa2377a00 Launching thread(s), CPUs 4
04-21 16:56:27.310  27318-27318/com.siliconmindtech.trofi I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@344b9848 time:13859270
04-21 16:56:29.700  27318-27318/com.siliconmindtech.trofi D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-21 16:56:31.850  27318-27318/com.siliconmindtech.trofi D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
04-21 16:56:31.970  27318-27318/com.siliconmindtech.trofi I/Places﹕ Got here!
04-21 16:56:32.300  27318-27350/com.siliconmindtech.trofi D/OpenGLRenderer﹕ endAllStagingAnimators on 0xa196d600 (InsetDrawable) with handle 0xaf7fc350
04-21 16:56:32.740  27318-27318/com.siliconmindtech.trofi I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@344b9848 time:13864703

上述LogCat是Verbose。

解决方案:不要像我这样的新手,我忘了将我的Google API密钥添加到我的android_manifest.xml …我道歉。

只需在Google开发者控制台中启用Google Places API for Android。

不要忘记在AndroidManifest上指定您的API密钥:

<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="ADD_YOUR_API_KEY_HERE" />
http://stackoverflow.com/questions/29781978/google-placepicker-closes-immediately-after-launch

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Android – Google PlacePicker在启动后立即关闭