java – Google Places API在发布后崩溃

前端之家收集整理的这篇文章主要介绍了java – Google Places API在发布后崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

Java类:

  1. package lgalle19.developements.findplaces;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.ActionBarActivity;
  6. import android.text.Html;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.TextView;
  10. import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
  11. import com.google.android.gms.common.GooglePlayServicesRepairableException;
  12. import com.google.android.gms.location.places.Place;
  13. import com.google.android.gms.location.places.ui.PlacePicker;
  14. public class PlacePickerActivity extends ActionBarActivity {
  15. private static final int PLACE_PICKER_REQUEST = 1;
  16. private TextView mViewName;
  17. private TextView mViewAddress;
  18. private TextView mViewAttributions;
  19. private Button mPickerButton;
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_place_picker);
  24. mViewName = (TextView) findViewById(R.id.textView);
  25. mViewAddress = (TextView) findViewById(R.id.textView2);
  26. mViewAttributions = (TextView) findViewById(R.id.textView3);
  27. mPickerButton = (Button) findViewById(R.id.pickerButton);
  28. }
  29. public void onPickButtonClick(View v) {
  30. // Construct an intent for the place picker
  31. try {
  32. PlacePicker.IntentBuilder intentBuilder =
  33. new PlacePicker.IntentBuilder();
  34. Intent intent = intentBuilder.build(this);
  35. // Start the intent by requesting a result,// identified by a request code.
  36. startActivityForResult(intent,PLACE_PICKER_REQUEST);
  37. } catch (Exception e){
  38. e.printStackTrace();
  39. }
  40. }
  41. @Override
  42. protected void onActivityResult(int requestCode,int resultCode,Intent data) {
  43. if (requestCode == PLACE_PICKER_REQUEST
  44. && resultCode == Activity.RESULT_OK) {
  45. // The user has selected a place. Extract the name and address.
  46. final Place place = PlacePicker.getPlace(data,this);
  47. final CharSequence name = place.getName();
  48. final CharSequence address = place.getAddress();
  49. String attributions = PlacePicker.getAttributions(data);
  50. if (attributions == null) {
  51. attributions = "";
  52. }
  53. mViewName.setText(name);
  54. mViewAddress.setText(address);
  55. mViewAttributions.setText(Html.fromHtml(attributions));
  56. } else {
  57. super.onActivityResult(requestCode,resultCode,data);
  58. }
  59. }
  60. }

主XML:

表现:

  1. required="true" />

摇篮:

  1. apply plugin: 'com.android.application'
  2. android {
  3. compileSdkVersion 22
  4. buildToolsVersion "22.0.1"
  5. defaultConfig {
  6. applicationId "lgalle19.developements.findplaces"
  7. minSdkVersion 15
  8. targetSdkVersion 22
  9. versionCode 1
  10. versionName "1.0"
  11. }
  12. buildTypes {
  13. release {
  14. minifyEnabled false
  15. proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
  16. }
  17. }
  18. }
  19. dependencies {
  20. compile fileTree(dir: 'libs',include: ['*.jar'])
  21. compile 'com.android.support:appcompat-v7:22.0.0'
  22. compile 'com.google.android.gms:play-services:7.5.0'
  23. }

logcat的:

  1. 08-07 13:25:37.053 29527-29527/lgalle19.developements.findplaces E/Zygote MountEmulatedStorage()
  2. 08-07 13:25:37.053 29527-29527/lgalle19.developements.findplaces E/Zygote v2
  3. 08-07 13:25:37.053 29527-29527/lgalle19.developements.findplaces I/libpersona KNOX_SDCARD checking this for 10245
  4. 08-07 13:25:37.053 29527-29527/lgalle19.developements.findplaces I/libpersona KNOX_SDCARD not a persona
  5. 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
  6. 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
  7. 08-07 13:25:37.063 29527-29527/lgalle19.developements.findplaces E/SELinux [DEBUG] get_category: variable seinfo: default sensitivity: NULL,cateogry: NULL
  8. 08-07 13:25:37.063 29527-29527/lgalle19.developements.findplaces I/art Late-enabling -Xcheck:jni
  9. 08-07 13:25:37.083 29527-29527/lgalle19.developements.findplaces D/TimaKeyStoreProvider TimaSignature is unavailable
  10. 08-07 13:25:37.083 29527-29527/lgalle19.developements.findplaces D/ActivityThread Added TimaKeyStore provider
  11. 08-07 13:25:37.153 29527-29527/lgalle19.developements.findplaces I/InjectionManager Inside getClassLibPath + mLibMap{0=,1=}
  12. 08-07 13:25:37.163 29527-29527/lgalle19.developements.findplaces I/InjectionManager Inside getClassLibPath caller
  13. 08-07 13:25:37.203 29527-29527/lgalle19.developements.findplaces D/InjectionManager InjectionManager
  14. 08-07 13:25:37.203 29527-29527/lgalle19.developements.findplaces D/InjectionManager fillFeatureStoreMap lgalle19.developements.findplaces
  15. 08-07 13:25:37.213 29527-29527/lgalle19.developements.findplaces I/InjectionManager Constructor lgalle19.developements.findplaces,Feature store :{}
  16. 08-07 13:25:37.213 29527-29527/lgalle19.developements.findplaces I/InjectionManager featureStore :{}
  17. 08-07 13:25:37.273 29527-29527/lgalle19.developements.findplaces D/PhoneWindow *FMB* installDecor mIsFloating : false
  18. 08-07 13:25:37.273 29527-29527/lgalle19.developements.findplaces D/PhoneWindow *FMB* installDecor flags : -2139029248
  19. 08-07 13:25:37.333 29527-29527/lgalle19.developements.findplaces D/Activity performCreate Call Injection manager
  20. 08-07 13:25:37.333 29527-29527/lgalle19.developements.findplaces I/InjectionManager dispatchOnViewCreated > Target : lgalle19.developements.findplaces.PlacePickerActivity isFragment :false
  21. 08-07 13:25:37.353 29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer Render dirty regions requested: true
  22. 08-07 13:25:37.363 29527-29527/lgalle19.developements.findplaces D/PhoneWindow *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
  23. 08-07 13:25:37.363 29527-29527/lgalle19.developements.findplaces D/PhoneWindow *FMB* isFloatingMenuEnabled return false
  24. 08-07 13:25:37.473 29527-29561/lgalle19.developements.findplaces D/libEGL loaded /vendor/lib64/egl/libGLES_mali.so
  25. 08-07 13:25:37.513 29527-29561/lgalle19.developements.findplaces I/OpenGLRenderer Initialized EGL,version 1.4
  26. 08-07 13:25:37.523 29527-29561/lgalle19.developements.findplaces I/OpenGLRenderer HWUI protection enabled for context,&this =0x7fa4c75060,&mEglDisplay = 1,&mEglConfig = -1529904464
  27. 08-07 13:25:37.523 29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer Get maximum texture size. GL_MAX_TEXTURE_SIZE is 8192
  28. 08-07 13:25:37.523 29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer Enabling debug mode 0
  29. 08-07 13:25:37.523 29527-29561/lgalle19.developements.findplaces D/mali_winsys new_window_surface returns 0x3000,[1440x2560]-format:1
  30. 08-07 13:25:37.553 29527-29527/lgalle19.developements.findplaces I/InjectionManager dispatchCreateOptionsMenu :lgalle19.developements.findplaces.PlacePickerActivity
  31. 08-07 13:25:37.553 29527-29527/lgalle19.developements.findplaces I/InjectionManager dispatchPrepareOptionsMenu :lgalle19.developements.findplaces.PlacePickerActivity
  32. 08-07 13:25:37.673 29527-29527/lgalle19.developements.findplaces I/Timeline Timeline: Activity_idle id: android.os.BinderProxy@3d2a49fa time:246449518
  33. 08-07 13:25:42.163 29527-29527/lgalle19.developements.findplaces D/ViewRootImpl ViewPostImeInputStage ACTION_DOWN
  34. 08-07 13:25:42.813 29527-29561/lgalle19.developements.findplaces D/OpenGLRenderer endAllStagingAnimators on 0x7faaf61e00 (RippleDrawable) with handle 0x7f966ee140
  35. 08-07 13:25:46.713 29527-29561/lgalle19.developements.findplaces D/mali_winsys new_window_surface returns 0x3000,[1440x2560]-format:1
  36. 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密钥添加到我的清单中,所以我的问题似乎有所不同.

任何帮助是极大的赞赏!

最佳答案
编辑:

将元数据标记更改为

  1. <Meta-data
  2. android:name="com.google.android.geo.API_KEY"
  3. android:value="@string/google_api_key"/>

并将您的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.

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

猜你在找的Java相关文章