java – Google Places API在发布后崩溃

我一直在尝试将Google Places API集成到我的应用程序中,但似乎无法启动API.每次单击按钮启动API时,它都会加载,然后恢复到主屏幕.我相信我已经遵循了API文档中的所有步骤,但似乎似乎无法找到问题.我的代码如下:

Java类:

package lgalle19.developements.findplaces;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.ui.PlacePicker;


public class PlacePickerActivity extends ActionBarActivity {
private static final int PLACE_PICKER_REQUEST = 1;
private TextView mViewName;
private TextView mViewAddress;
private TextView mViewAttributions;
private Button mPickerButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_place_picker);

    mViewName = (TextView) findViewById(R.id.textView);
    mViewAddress = (TextView) findViewById(R.id.textView2);
    mViewAttributions = (TextView) findViewById(R.id.textView3);
    mPickerButton = (Button) findViewById(R.id.pickerButton);
}

public void onPickButtonClick(View v) {
    // Construct an intent for the place picker
    try {
        PlacePicker.IntentBuilder intentBuilder =
                new PlacePicker.IntentBuilder();
        Intent intent = intentBuilder.build(this);
        // Start the intent by requesting a result,// identified by a request code.
        startActivityForResult(intent,PLACE_PICKER_REQUEST);

    } catch (Exception e){
        e.printStackTrace();
    }
}

@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {

    if (requestCode == PLACE_PICKER_REQUEST
            && resultCode == Activity.RESULT_OK) {

        // The user has selected a place. Extract the name and address.
        final Place place = PlacePicker.getPlace(data,this);

        final CharSequence name = place.getName();
        final CharSequence address = place.getAddress();
        String attributions = PlacePicker.getAttributions(data);
        if (attributions == null) {
            attributions = "";
        }

        mViewName.setText(name);
        mViewAddress.setText(address);
        mViewAttributions.setText(Html.fromHtml(attributions));

    } else {
        super.onActivityResult(requestCode,resultCode,data);
    }
}
}

主XML:

表现:

摇篮:

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "lgalle19.developements.findplaces"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs',include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.5.0'
}

logcat的:

08-07 13:25:37.053  29527-29527/lgalle19.developements.findplaces E/Zygote﹕ MountEmulatedStorage()
08-07 13:25:37.053  29527-29527/lgalle19.developements.findplaces E/Zygote﹕ v2
08-07 13:25:37.053  29527-29527/lgalle19.developements.findplaces I/libpersona﹕ KNOX_SDCARD checking this for 10245
08-07 13:25:37.053  29527-29527/lgalle19.developements.findplaces I/libpersona﹕ KNOX_SDCARD not a persona
08-07 13:25:37.053  29527-29527/lgalle19.developements.findplaces I/SELinux﹕ Function: selinux_compare_spd_ram,SPD-policy is existed. and_ver=SEPF_SM-G920V_5.0.2 ver=27
08-07 13:25:37.063  29527-29527/lgalle19.developements.findplaces I/SELinux﹕ Function: selinux_compare_spd_ram,priority [1],priority version is VE=SEPF_SM-G920V_5.0.2_0027
08-07 13:25:37.063  29527-29527/lgalle19.developements.findplaces E/SELinux﹕ [DEBUG] get_category: variable seinfo: default sensitivity: NULL,cateogry: NULL
08-07 13:25:37.063  29527-29527/lgalle19.developements.findplaces I/art﹕ Late-enabling -Xcheck:jni
08-07 13:25:37.083  29527-29527/lgalle19.developements.findplaces D/TimaKeyStoreProvider﹕ TimaSignature is unavailable
08-07 13:25:37.083  29527-29527/lgalle19.developements.findplaces D/ActivityThread﹕ Added TimaKeyStore provider
08-07 13:25:37.153  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ Inside getClassLibPath + mLibMap{0=,1=}
08-07 13:25:37.163  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ Inside getClassLibPath caller
08-07 13:25:37.203  29527-29527/lgalle19.developements.findplaces D/InjectionManager﹕ InjectionManager
08-07 13:25:37.203  29527-29527/lgalle19.developements.findplaces D/InjectionManager﹕ fillFeatureStoreMap lgalle19.developements.findplaces
08-07 13:25:37.213  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ Constructor lgalle19.developements.findplaces,Feature store :{}
08-07 13:25:37.213  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ featureStore :{}
08-07 13:25:37.273  29527-29527/lgalle19.developements.findplaces D/PhoneWindow﹕ *FMB* installDecor mIsFloating : false
08-07 13:25:37.273  29527-29527/lgalle19.developements.findplaces D/PhoneWindow﹕ *FMB* installDecor flags : -2139029248
08-07 13:25:37.333  29527-29527/lgalle19.developements.findplaces D/Activity﹕ performCreate Call Injection manager
08-07 13:25:37.333  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ dispatchOnViewCreated > Target : lgalle19.developements.findplaces.PlacePickerActivity isFragment :false
08-07 13:25:37.353  29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer﹕ Render dirty regions requested: true
08-07 13:25:37.363  29527-29527/lgalle19.developements.findplaces D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
08-07 13:25:37.363  29527-29527/lgalle19.developements.findplaces D/PhoneWindow﹕ *FMB* isFloatingMenuEnabled return false
08-07 13:25:37.473  29527-29561/lgalle19.developements.findplaces D/libEGL﹕ loaded /vendor/lib64/egl/libGLES_mali.so
08-07 13:25:37.513  29527-29561/lgalle19.developements.findplaces I/OpenGLRenderer﹕ Initialized EGL,version 1.4
08-07 13:25:37.523  29527-29561/lgalle19.developements.findplaces I/OpenGLRenderer﹕ HWUI protection enabled for context,&this =0x7fa4c75060,&mEglDisplay = 1,&mEglConfig = -1529904464
08-07 13:25:37.523  29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer﹕ Get maximum texture size. GL_MAX_TEXTURE_SIZE is 8192
08-07 13:25:37.523  29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer﹕ Enabling debug mode 0
08-07 13:25:37.523  29527-29561/lgalle19.developements.findplaces D/mali_winsys﹕ new_window_surface returns 0x3000,[1440x2560]-format:1
08-07 13:25:37.553  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ dispatchCreateOptionsMenu :lgalle19.developements.findplaces.PlacePickerActivity
08-07 13:25:37.553  29527-29527/lgalle19.developements.findplaces I/InjectionManager﹕ dispatchPrepareOptionsMenu :lgalle19.developements.findplaces.PlacePickerActivity
08-07 13:25:37.673  29527-29527/lgalle19.developements.findplaces I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3d2a49fa time:246449518
08-07 13:25:42.163  29527-29527/lgalle19.developements.findplaces D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
08-07 13:25:42.813  29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer﹕ endAllStagingAnimators on 0x7faaf61e00 (RippleDrawable) with handle 0x7f966ee140
08-07 13:25:46.713  29527-29561/lgalle19.developements.findplaces D/mali_winsys﹕ new_window_surface returns 0x3000,[1440x2560]-format:1
08-07 13:25:46.813  29527-29527/lgalle19.developements.findplaces I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3d2a49fa time:246458658

我也一定要在开发者控制台上启用适用于Android的Google Places API,并创建一个我存储Manifest的API密钥.这里发布的主题Google PlacePicker Closes Immediately After Launch似乎与我的类似问题,但我已经将我的API密钥添加到我的清单中,所以我的问题似乎有所不同.

任何帮助是极大的赞赏!

最佳答案
编辑:

将元数据标记更改为

并将您的api密钥作为资源而不是硬编码引用

编辑:

获取应用程序标记之外的权限.

像这样嵌套:

尝试将此添加到您的清单:

这是一个很好的教程:

http://code.tutsplus.com/articles/google-play-services-using-the-places-api–cms-23715

该问题Google Places API for Android Place Picker Does not work描述了类似的问题
而它的answer给出了一个很好的方向.

make sure you enable “Places API for Android” and not just “Places
API” in the Developer Console. “Places API for Android” will not show
up under “APIs & Auth/APIs” because it isnt a popular API (yet). You
will have to search for it using the API search box.

让我知道如果这解决了你的问题,如果不是,我们可以再看看.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


本文从从Bitcask存储模型讲起,谈轻量级KV系统设计与实现。从来没有最好的K-V系统,只有最适合应用业务实际场景的系统,做任何的方案选择,要结合业务当前的实际情况综合权衡,有所取有所舍。
内部的放到gitlab pages的博客,需要统计PV,不蒜子不能准确统计,原因在于gitlab的host设置了strict-origin-when-cross-origin, 导致不蒜子不能正确获取referer,从而PV只能统计到网站的PV。 为了方便统计页面的PV,这里简单的写了一个java程
PCM 自然界中的声音非常复杂,波形极其复杂,通常我们采用的是脉冲代码调制编码,即PCM编码。PCM通过抽样、量化、编码三个步骤将连续变化的模拟信号转换为数字编码。 采样率 采样频率,也称为采样速度或者采样率,定义了每秒从连续信号中提取并组成离散信号的采样个数,它用赫兹(Hz)来表示。采样频率的倒数
本文介绍如何离线生成sst并在线加载,提供一种用rocksdb建立分布式kv系统替换mongodb的思路
验证用户输入是否正确是我们应用程序中的常见功能。Spring提供了`@Valid`和@`Validated`两个注解来实现验证功能,本文详细介绍 [@Valid]和[@Validated]注解的区别 。
引入pdf2dom <dependency> <groupId>net.sf.cssbox</groupId> <artifactId>pdf2dom</artifactId> <version>1.8</version&
grafana 是一款非常优秀的可视化报表工具,有设计精良的可视化工具,今天来聊一聊如何将grafana集成到自己的应用中。 原理是: grafana允许iframe访问,开启auth.proxy, java 后端鉴权后代理grafana 前端通过iframe访问后端代理过的grafana graf
介绍 Call Graph是一款IDEA插件,用于可视化基于IntelliJ平台的IDE的函数调用图。 这个插件的目标是让代码更容易理解,有助于读懂和调试代码。当前只支持Java。针对Typescript、Javascript或Python工具,可以使用作者的另外一款工具Codemap(https:
原理 通过线程安全findAndModify 实现锁 实现 定义锁存储对象: /** * mongodb 分布式锁 */ @Data @NoArgsConstructor @AllArgsConstructor @Document(collection = "distributed-loc
Singleton 单例模式 单例模式是确保每个应用程序只存在一个实例的机制。默认情况下,Spring将所有bean创建为单例。 你用@Autowired获取的bean,全局唯一。 @RestController public class LibraryController { @Autowired
pipeline 分布式任务调度器 目标: 基于docker的布式任务调度器, 比quartzs,xxl-job 更强大的分布式任务调度器。 可以将要执行的任务打包为docker镜像,或者选择已有镜像,自定义脚本程序,通过pipeline框架来实现调度。 开源地址: https://github.c
python训练的模型,转换为onnx模型后,用python代码可以方便进行推理,但是java代码如何实现呢? 首先ONNX 推理,可以使用`onnxruntime` ```xml com.microsoft.onnxruntime onnxruntime 1.15.1 ``` 另外,训练的模型需要
要获取内网地址,可以尝试连接到10.255.255.255:1。如果连接成功,获取本地套接字的地址信息就是当前的内网IP。 python实现: ```python import socket def extract_ip(): st = socket.socket(socket.AF_INET, s
为什么要有索引 gremlin 其实是一个逐级过滤的运行机制,比如下面的一个简单的gremlin查询语句: g.V().hasLabel("label").has("prop","value") 运行原理就是: 找出所有的顶点V 然后过滤出
最近在分析一个应用中的某个接口的耗时情况时,发现一个看起来极其普通的对象创建操作,竟然每次需要消耗 8ms 左右时间,分析后发现这个对象可以通过对象池模式进行优化,优化后此步耗时仅有 0.01ms。
点赞再看,动力无限。Hello world : ) 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码网站 已经收录,有很多知识点和系列文章。 此篇文章介绍 Java JMX 技术的相关概念和具体的使用方式。 当前文章属于Java 性能分析优化系列
如何将Java JAR 转化为 win/mac/linux 独立可执行程序?不需要预装 JRE 运行?
点赞再看,动力无限。 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章。 Java 19 在2022 年 9 月 20 日正式发布,Java 19 不是一个长期支持版本,直到 2023 年 3 月它将被 JD
点赞再看,动力无限。Hello world : ) 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章。 前言 Java 反编译,一听可能觉得高深莫测,其实反编译并不是什么特别高级的操作,Java 对于 Cla
JSON 对于开发者并不陌生,如今的 WEB 服务、移动应用、甚至物联网大多都是以 **JSON** 作为数据交换的格式。学习 JSON 格式的操作工具对开发者来说是必不可少的。这篇文章将介绍如何使用 **Jackson** 开源工具库对 JSON 进行常见操作。