android - 即使现在已弃用,如何使用 Place Picker?

标签 android google-maps-api-3 google-places-api gmsplacepicker

<分区>

我现在正在开发一个应用程序,我正在使用地点选择器,但现在它已被弃用。我想在我的应用程序中继续使用它,直到它完全消失。我需要做什么?

我尝试使用 places 的 compat 库,但出现编译错误。


应用模块:

   buildscript {
    repositories {
         maven { url 'https://maven.fabric.io/public' }
     }

     dependencies {
         classpath 'io.fabric.tools:gradle:1.+'
     } } apply plugin: 'com.android.application' apply plugin: 'io.fabric'

 android {
     compileSdkVersion 27
     defaultConfig {
         applicationId "com.lim.therapist"
         minSdkVersion 21
         targetSdkVersion 27
         versionCode 2
         versionName "1.1"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     } } ext {
     permissionsDispatcherVersion = '2.2.0' }

 repositories {
     maven { url 'https://jitpack.io' }
     maven { url 'https://maven.fabric.io/public' } } dependencies {
     implementation "com.github.hotchemi:permissionsdispatcher:${permissionsDispatcherVersion}"
     implementation 'com.android.support:support-v4:27.1.1'
     annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:${permissionsDispatcherVersion}"
     implementation fileTree(include: ['*.jar'], dir: 'libs')
     //noinspection GradleCompatible
     implementation 'com.android.support:appcompat-v7:27.1.1'
     implementation 'com.android.support.constraint:constraint-layout:1.1.0'
     implementation 'com.android.support:design:27.1.0'
     implementation 'com.cocosw:bottomsheet:1.+@aar'
     implementation 'com.isseiaoki:simplecropview:1.1.4'
     implementation 'com.github.bumptech.glide:glide:3.7.0'
     implementation 'com.github.florent37:singledateandtimepicker:1.2.2'
     implementation 'de.hdodenhof:circleimageview:2.0.0'
     implementation 'com.android.support:multidex:1.0.1'
     implementation 'com.amitshekhar.android:android-networking:1.0.0'
     implementation 'com.google.code.gson:gson:2.8.2'
     implementation 'org.jsoup:jsoup:1.8.1'
     implementation 'com.github.hani-momanii:SuperNova-Emoji:1.1'
     implementation 'com.android.support:recyclerview-v7:27.1.1'
     implementation 'com.android.support:cardview-v7:27.1.1'
     implementation 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
     implementation 'com.google.firebase:firebase-messaging:11.8.0'
     implementation 'com.google.firebase:firebase-core:11.8.0'
     implementation 'com.google.android.gms:play-services:11.8.0'
     implementation 'com.google.android.gms:play-services-maps:11.8.0'
     implementation 'com.google.android.gms:play-services-location:11.8.0'

     implementation 'com.kyleduo.switchbutton:library:1.4.5'
     implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'
     implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
         transitive = true;
     } }

 apply plugin: 'com.google.gms.google-services'


项目模块:

// Top-level build file where you can add configuration options common
to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    } }



allprojects {
    repositories {
        google()
        jcenter()
    } }

task clean(type: Delete) {
    delete rootProject.buildDir }


日志:

 019-02-14 03:09:18.684 28156-28156/com.lim.therapist E/AndroidRuntime:
 FATAL EXCEPTION: main Process: com.lim.therapist, PID: 28156
 java.lang.RuntimeException: Failure delivering result
 ResultInfo{who=null, request=65637, result=2, data=null} to activity
 {com.lim.therapist/com.lim.therapist.ui.activity.BaseActivity}:
 java.lang.NullPointerException: intent must not be null at
 android.app.ActivityThread.deliverResults(ActivityThread.java:4271) at
 android.app.ActivityThread.handleSendResult(ActivityThread.java:4315)
 at android.app.ActivityThread.-wrap19(Unknown Source:0) at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1647)
 at android.os.Handler.dispatchMessage(Handler.java:106) at
 android.os.Looper.loop(Looper.java:164) at
 android.app.ActivityThread.main(ActivityThread.java:6518) at
 java.lang.reflect.Method.invoke(Native Method) at
 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused
 by: java.lang.NullPointerException: intent must not be null at
 com.google.android.gms.common.internal.zzbq.checkNotNull(Unknown
 Source:9) at
 com.google.android.gms.location.places.ui.zza.getStatus(Unknown
 Source:2) at
 com.google.android.gms.location.places.ui.PlaceAutocomplete.getStatus(Unknown
 Source:0) at
 com.lim.therapist.ui.fragment.ArtistProfileView.onActivityResult(ArtistProfileView.java:491)
 at
 android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
 at
 com.lim.therapist.ui.activity.BaseActivity.onActivityResult(BaseActivity.java:523)
 at android.app.Activity.dispatchActivityResult(Activity.java:7280) at
 android.app.ActivityThread.deliverResults(ActivityThread.java:4267) at
 android.app.ActivityThread.handleSendResult(ActivityThread.java:4315) 
 at android.app.ActivityThread.-wrap19(Unknown Source:0)  at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1647) 
 at android.os.Handler.dispatchMessage(Handler.java:106)  at
 android.os.Looper.loop(Looper.java:164)  at
 android.app.ActivityThread.main(ActivityThread.java:6518)  at
 java.lang.reflect.Method.invoke(Native Method)  at
 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
 2019-02-14 03:09:18.981 28156-28156/com.lim.therapist
 E/UncaughtException: java.lang.RuntimeException: Failure delivering
 result ResultInfo{who=null, request=65637, result=2, data=null} to
 activity
 {com.lim.therapist/com.lim.therapist.ui.activity.BaseActivity}:
 java.lang.NullPointerException: intent must not be null at
 android.app.ActivityThread.deliverResults(ActivityThread.java:4271) at
 android.app.ActivityThread.handleSendResult(ActivityThread.java:4315)
 at android.app.ActivityThread.-wrap19(Unknown Source:0) at
 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1647)
 at android.os.Handler.dispatchMessage(Handler.java:106) at
 android.os.Looper.loop(Looper.java:164) at
 android.app.ActivityThread.main(ActivityThread.java:6518) at
 java.lang.reflect.Method.invoke(Native Method) at
 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused
 by: java.lang.NullPointerException: intent must not be null at
 com.google.android.gms.common.internal.zzbq.checkNotNull(Unknown
 Source:9) at
 com.google.android.gms.location.places.ui.zza.getStatus(Unknown
 Source:2) at
 com.google.android.gms.location.places.ui.PlaceAutocomplete.getStatus(Unknown
 Source:0) at
 com.lim.therapist.ui.fragment.ArtistProfileView.onActivityResult(ArtistProfileView.java:491)
 at
 android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
 at
 com.lim.therapist.ui.activity.BaseActivity.onActivityResult(BaseActivity.java:523)
 at android.app.Activity.dispatchActivityResult(Activity.java:7280) at
 android.app.ActivityThread.deliverResults(ActivityThread.java:4267)

我想继续使用地点选择器。请帮我。我是 stackoverflow 的新手,对于任何不悦目的事情我深表歉意。谢谢

最佳答案

使用兼容库

    dependencies {
  implementation 'com.google.android.libraries.places:places-compat:1.0.0'
}

新客户端库不支持地点选取器。要在弃用期内继续使用 Place Picker,请务必安装兼容性库。

查看链接以获取更多信息。 Link

关于android - 即使现在已弃用,如何使用 Place Picker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54677148/

相关文章:

java - 一起使用 JavaCV 和 Realm 会导致 "java.lang.UnsatisfiedLinkError"

javascript - 如何在 ipad phonegap android eclipse 中关闭水合作用

google-maps-api-3 - 有没有办法使覆盖对象不可点击?

javascript - 如何使用谷歌地图 API 制作一个在特定半径范围内搜索项目的表单?

javascript - 无效值错误: setCenter : not a LatLng or LatLngLiteral Object

android - 谷歌地方 API : PLACES_API_INVALID_APP

ios - Google Places Autocomplete - 如何获得纬度和经度?

android - 抑制系统音量以从应用程序内部播放通知音频

swift - googlePlaces api 解析后给出错误的值

安卓声音验证