地点选择器启动后关闭

2024-01-12

我无法从我的片段启动 Google 地点选择器。 按照所有步骤和论坛查找根本原因,但无法解决我的问题。

Links 谷歌地点选择器 https://developers.google.com/places/android-api/placepicker
已经检查了以下但没有成功
Android 地点选择器启动后立即关闭 https://stackoverflow.com/questions/30067210/android-place-picker-closes-immediately-after-launch
地点选择器启动后自动关闭 https://stackoverflow.com/questions/30434238/place-picker-automatically-close-after-launch

我已经为 Android 密钥创建了 Google Places API 并添加到清单中

我什至尝试过发布版本。

我收到的唯一错误消息是

03-18 12:02:32.524 1679-1900/? E/GCoreFlp: Location requests inside Google 
Play services must contain a tag to aid in debugging.  Use LocationRequestInternal.create to wrap your LocationRequest, and pass it to requestLocationUpdates.
03-18 12:02:32.527 29916-29916/? E/PlacePicker: Place Picker closing due to ERROR

需要帮忙

我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tyagiabhinav.test">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="KEY-REMOVED-ON-STACKOVERFLOW" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我的 Gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.tyagiabhinav.test"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services-location:8.4.0'
}

我的片段代码

package com.tyagiabhinav.test;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.location.places.ui.PlacePicker;

/**
 * Created by abhinavtyagi on 18/03/16.
 */
public class MainFragment extends Fragment implements ConnectionCallbacks, OnConnectionFailedListener {

    private View rootView;
    private GoogleApiClient mGoogleApiClient;
    private boolean isLocationServiceConnected = false;
    private static final String LOG_TAG = MainFragment.class.getSimpleName();
    private static final int PLACE_PICKER_REQUEST = 7;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.main_fragment, container, false);
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .addApi(Places.GEO_DATA_API)
                    .addApi(Places.PLACE_DETECTION_API)
                    .build();
        }

        Button btn = (Button) rootView.findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(LOG_TAG, "Clicked");
                if (ContextCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.ACCESS_FINE_LOCATION)
                        != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION)
                        != PackageManager.PERMISSION_GRANTED) {
                    Log.d(LOG_TAG, "Ask for Permission");
                    // Should we show an explanation?
                    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) {

                        // Show an expanation to the user *asynchronously* -- don't block
                        // this thread waiting for the user's response! After the user
                        // sees the explanation, try again to request the permission.
                        requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, PLACE_PICKER_REQUEST);

                    } else {
                        // No explanation needed, we can request the permission.
                        requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, PLACE_PICKER_REQUEST);
                    }
                } else {
                    Log.d(LOG_TAG, "Permission Available");
                    placePicker();
                }
            }
        });
        return rootView;
    }


    private void placePicker() {
        if (isLocationServiceConnected) {
            Log.d(LOG_TAG, "Connected to location service");
            PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
            try {
                Intent intent = intentBuilder.build(getActivity());
                startActivityForResult(intent, PLACE_PICKER_REQUEST);
            } catch (GooglePlayServicesRepairableException e) {
                e.printStackTrace();
            } catch (GooglePlayServicesNotAvailableException e) {
                e.printStackTrace();
            }
        } else {
            Log.d(LOG_TAG, "Not connected to location service");
            Toast.makeText(getActivity(), "Not connected to location service", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        Log.d(LOG_TAG, "onRequestPermissionsResult");
        switch (requestCode) {
            case PLACE_PICKER_REQUEST: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.d(LOG_TAG, "Permission Granted");
                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.
                    placePicker();

                } else {
                    Log.d(LOG_TAG, "Permission Denied");
                    // permission denied, boo! Disable the
                    // functionality that depends on this permission.
                    Toast.makeText(getActivity(), "Location Permission is required for accessing Place Picker!", Toast.LENGTH_LONG).show();
                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }


    @Override
    public void onStart() {
        super.onStart();
        if (mGoogleApiClient != null)
            mGoogleApiClient.connect();
    }

    @Override
    public void onStop() {
        if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
        super.onStop();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.d(LOG_TAG, "Location Connection Failed");
        isLocationServiceConnected = false;
    }

    @Override
    public void onConnected(Bundle bundle) {
        Log.d(LOG_TAG, "Location Service Connected");
        isLocationServiceConnected = true;
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d(LOG_TAG, "Location Service Suspended");
        isLocationServiceConnected = false;
    }


}

错误地放置了元数据标签

更正清单文件:P

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tyagiabhinav.test">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="KEY-REMOVED-ON-STACKOVERFLOW" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

地点选择器启动后关闭 的相关文章

  • gradle更新后无法找到方法(无法编译项目)

    我尝试将项目中的 gradle 版本更新为 4 1 milestone 1 以下这些说明 https developer android com studio build gradle plugin 3 0 0 migration html
  • 按下按钮时应用不同的样式

    有没有办法在按下按钮时将样式应用于按钮 如果我有一种风格样式 xml
  • Android 初学者:Android gridview 中的触摸事件

    我正在使用以下代码来使用 gridview 执行操作 稍作修改http developer android com resources tutorials views hello gridview html http developer a
  • Android应用程序组件销毁和重新创建的详细信息

    有人可以向我提供一些具体的 值得信赖的 最好是简洁的 信息 内容如下 系统销毁和 如果适用 重新创建组件的顺序 片段 活动 活动的线程 异步任务 计时器 静态数据 类何时卸载 其他类中的线程 异步任务 定时器 主机 TabActivity
  • 如何更改终端的默认目录?

    我想更改 Android Studio v2 2 2 终端的默认目录 当我打开终端时 它基于项目的目录 C 项目路径 我经常需要使用adb shell 所以我必须导航到 SDK 路径 平台工具 才能使用 adb 命令 是否可以更改终端的默认
  • ExoPlayer2 - 如何使 HTTP 301 重定向工作?

    我开始使用 ExoPlayer 来传输一些音频 一切都很顺利 直到我遇到一个带有 301 永久移动 重定向的 URL ExoPlayer2 默认情况下不处理该问题 我已经看过这个线程 https github com google ExoP
  • Android 深度链接至 Instagram 应用

    Instagram 已经发布了 iOS 深层链接的 url 方案 但尚未为 Android 创建文档 有没有办法深入链接到 Android 上的 Instagram 应用程序 以转到 Instagram 应用程序中的特定位置 例如 Inst
  • 从 BroadcastReceiver 类调用活动方法

    我知道我可以做一个内部接收器类来调用接收器中的任何方法 但我的主要活动太大了 要做的事情也很多 因此 我需要一个扩展广播接收器的类 但它不是内部类 并且可以从我的主要活动中调用一种方法 我不知道是否可能 但我的活动是家庭活动和 single
  • 使用片段时应用程序崩溃

    我正在处理碎片和 我的代码中有一个我找不到的问题 logcat 指向我的一个片段中的这段代码 Override public View onCreateView LayoutInflater inflater ViewGroup conta
  • 对于一个单元格,RecyclerView onBindViewHolder 调用次数过多

    我正在将 RecyclerView 与 GridLayoutManager 一起使用 对于网格中的每个项目 我需要调用 REST api 来检索数据 然后 从远程异步获取数据后 我使用 UIL 加载 显示图像 一切似乎都很好 但我发现 on
  • Android 2.3 模拟器在更新位置时崩溃

    我正在使用 Eclipse 编写和调试 Android 应用程序 我需要做的事情之一是更新设备的位置 因此我尝试使用模拟器控制窗口中的位置控制面板 在 手动 选项卡上 我选择 十进制 输入有效的纬度和经度 然后单击 发送 不幸的是 接下来发
  • 我应该释放或重置 MediaPlayer 吗?

    我有自己的自定义适配器类 称为 WordAdapter 并且我正在使用媒体播放器 名为pronounce WordAdapter 类中的全局变量 我有不同的活动 其中每个列表项都有线性布局 名为linearLayout 我正在设置onCli
  • Android 如何将总天数准确更改为年、月、日?

    我正在做一个应用程序 该应用程序与根据给定的生日日期输入获取一个人的年龄有关 为此 我从下面的代码中获取从该日期到当前日期的总天数 String strThatDay 1991 05 10 SimpleDateFormat formatte
  • 如何检查 Android 中的同步设置

    我正在构建一个 Android 应用程序 我需要检查设备中注册的每个单独帐户的同步设置 我知道我可以通过 ContentResolver 类来做到这一点 但我遇到了一些问题 我已设法获取设备上所有帐户的列表 但我不知道在运行时从哪里获取特定
  • 没有用于警告的设置器/字段 Firebase 数据库检索数据填充列表视图

    我只是想将 Firebase 数据库中的数据填充到我的列表视图中 日志显示正在检索数据 但适配器不会将值设置为列表中单个列表项中的文本 它只说 没有二传手 场地插入值 这让我觉得我的设置器没有正确制作 但 Android Studio 自动
  • 插件“Android Bundle Support”不兼容

    大家好 自从上次更新以来 当我启动 android studio 时 我遇到了一个非常奇怪的错误 我有这个错误 插件错误 插件 Android Bundle Support 不兼容 直到构建 AI 195 SNAPSHOT 我在网上找不到任
  • 问题:为什么React Native Video不能全屏播放视频?

    我正在react native 0 57 7 中为android和ios创建一个应用程序并使用反应本机视频 https github com react native community react native video播放上传到的视频
  • Dagger 2 中“HasFragmentInjector”的实际用法是什么

    我之前已经实现了 dagger2 v2 2 但现在他们也添加了 dagger android 部分 所以我正在用它创建示例项目 我知道旧的方法论 Provide and Modules and 成分等注释 但从 Dagger 2 8 开始
  • Android 后台倒计时器

    我有一个 Android 应用程序 它管理一个倒计时器 类 CountDownTimer 它显示在应用程序屏幕中 以显示到达 00 00 还剩多少时间 我现在的问题是 当我按主页按钮或启动另一个应用程序时 应用程序 计时器不会在后台运行 所
  • Git 实验分支还是单独的实验存储库?

    我正在开发一个 Android 应用程序 并且在整个开发周期中一直使用 Git 现在 我想构建并发布实验性功能 供人们尝试和安装 同时仍将原始的 稳定的应用程序安装在他们的设备上 现在 这意味着我需要使用不同的包名称 这会更改开发项目中的一

随机推荐

  • 绑定:在“YYY”上找不到“XXX”属性,目标属性:“Xamarin.Forms.Label.Text”

    我正在使用 Xamarin Forms 和 MVVM 我在日志中收到以下内容 绑定 在 YYY 上找不到 XXX 属性 目标属性 Xamarin Forms Label Text 不确定它是否相关 但是当我更新命令函数中的变量时 该变量的更
  • React:将 props 传递给函数组件

    我有一个关于道具和功能组件的看似微不足道的问题 基本上 我有一个容器组件 它在用户单击按钮触发的状态更改时呈现模态组件 模态是一个无状态函数组件 其中包含一些需要连接到容器组件内部函数的输入字段 我的问题 当用户与无状态模态组件内的表单字段
  • IndexedDB回调不更新AngularJS中的UI

    我正在使用以下库在新的 Chrome 应用程序上访问 Angularjs 中的 IndexedDB https github com aaronpowell db js https github com aaronpowell db js
  • 左右滑动可更改活动

    所以我有一个活动 其中有一个导航抽屉 我停用了滑动以打开该导航抽屉 仅当我单击该菜单的按钮时它才会打开 现在我想通过滑动来更改活动 就像在 iPhone 中一样 我已经这样做了 但我不确定这是正确的方法 这是我的代码 GestureDete
  • Installshield - 使用 powershell 检查注册表中的密钥失败

    我有一个带有 powershell CA 的 Installshield 项目 它检查某个注册表项是否存在并根据结果设置属性 手动执行脚本时注册表检查成功但失败 返回false当从Installshield执行时 CA 在 UI 序列期间执
  • 将.apk文件发送给客户审核

    我开发了一个 Android 应用程序 并在模拟器和设备上对其进行了测试 我想将 apk文件导出到客户端进行审核 我使用应用程序清单文件导出未签名的 apk 并将其发送 但它没有安装在他的手机上 我在这里阅读了多个问题 但没有得到任何具体信
  • jwt.verify() 的 Node.js 回调

    我的 Node js 服务器上有一个身份验证路由 用于对请求进行身份验证 app get loggedin auth function req res console log req authenticated res send req a
  • SQLite eventim 的时间输入和时间退出

    我有两张桌子 DATA and EVENTS 具有以下数据 EVENTS EventIndex ObjID LocID EventData EventTime EventType 83707365 3519434 10376 0 2013
  • pandas to_numeric downcast='signed' 返回 float64

    我有一个数据集 其中 pandas read csv 处理适当地将一些连续数字列 特征 变量数据从对象转换为 float64 int64 或 uint8 但不是其他数据 因此 然后我尝试使用以下指定向下转换参数的 pandas to num
  • 如何使用 Javascript 停止 YouTube 中的视频?

    情况 here http yvoschaap com videowall q sunset 20beautiful我在那里按了一些视频 Problem 我尝试在 Firebug 控制台中通过 Javascript 停止视频 player s
  • 从另一个表和不同的数据库更新表

    基本上 我想做的是 我的第一个数据库 prc 中有一个表 users 如下所示 prc user id user 45 name user Test login user test pwd user test 在我的第二个数据库 名为 pr
  • 使用 awk 替换 CSV 文件中的列值

    我有这个文件 错误日志 00 00 00 284 501 00 00 00 417 5 5294100071980 00 00 02 463 501 00 00 05 169 501 00 00 05 529 501 00 00 05 73
  • Delphi - 通用 TList 排序

    我正在使用 Generics Collections TList 和 Sort 方法 它工作正常 但我想最后对空值或空值进行排序 按升序和降序排序 如何实施 这是我的排序功能 function TForm SortByColumn Colu
  • 按行项目条件更改 MudBlazor 表背景颜色

    我正在尝试更改 mudblazor 表中一行的颜色 问题是 我无法添加根据行元素的条件更改颜色的功能
  • WPF 中的 PagedCollectionView 等效项?

    net 3 5 或 4 0 中是否有像 Silverlight 中的 PagedCollectionView 这样的 WPF 等效类 不 没有 但你可以从这里获取 https silverlight svn codeplex com svn
  • 确定可能的项目组的算法

    我正在摸不着头脑试图做到这一点 这让我筋疲力尽 我知道事情没那么复杂 我有很多物品 这个数量可以等于或大于三 然后我需要确定完成总数的项目组的可能组合 唯一的限制是小组应该有三个或更多项目 不超过 但包括 七个项目 例如 如果我有 7 个项
  • 为单词的前 n 个字符添加下划线

    我想在链接中的单词的前几个字符下划线 类似于 CSS 第一个字母的工作方式 但字母数量可变 或者 在单词字母的前半部分下划线可能会很有用 有什么方法可以使用 HTML CSS 或 Javascript 相对简单地完成此操作吗 我不是开发人员
  • Uncrustify 折叠 多行函数调用

    我的函数调用如下所示 没有明显的原因 func a b c 有没有办法让 uncrustify 将函数折叠成一行 我已经尝试了两天了 没有断断续续的 我让它适用于函数声明 但我没有让它适用于函数调用 当我们这样做时 我也有如下所示的函数 f
  • 为什么是语句(j++);禁止?

    下面的代码是错误的 看一下关于ideone http ideone com vSoRsM public class Test public static void Main int j 5 j if we remove the and th
  • 地点选择器启动后关闭

    我无法从我的片段启动 Google 地点选择器 按照所有步骤和论坛查找根本原因 但无法解决我的问题 Links 谷歌地点选择器 https developers google com places android api placepick