Я не знаю почему, но открываю сборщик на мобильном телефоне android, но автоматически закрывается через 2 или 3 секунды. Я включаю api-ключ в консоль разработчика, а также ограничиваю его мобильным приложением, указав имя пакета и имя шага. Все хорошо, но за последние несколько часов я не знаю, почему он не работает.
Здесь я могу отправить подробности кода моего проекта. Пожалуйста, помогите мне, я пробовал много раз, но не могу найти какое-либо решение.,
Вот зависимости, которые я реализую в gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
И код для основной деятельности приведен ниже:
package com.spotech.placepickerdemo;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
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 MainActivity extends AppCompatActivity {
Button btnPlacePicker;
TextView txtLongitude,txtLatitude;
int PLACEPICKER_REQUEST = 1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnPlacePicker = (Button) findViewById(R.id.btnPlacePicker);
txtLongitude = (TextView) findViewById(R.id.longitudeplace);
txtLatitude = (TextView) findViewById(R.id.latitudeplace);
btnPlacePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
Intent intent = builder.build(MainActivity.this);
startActivityForResult(intent,PLACEPICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
e.toString();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (resultCode == PLACEPICKER_REQUEST){
if (resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(data,this);
String lat = String.valueOf(place.getLatLng().latitude);
String lon = String.valueOf(place.getLatLng().longitude);
String placeName = String.valueOf(place.getName());
txtLatitude.setText( "Latitude : "+ lat);
txtLongitude.setText("Longitude : "+lon);
Toast.makeText(this, placeName, Toast.LENGTH_SHORT).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Вот мой файл манифеста:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spotech.placepickerdemo">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBQHVoCdqQsRFP23dK9lENxEtZb0o3k1mw"
/>
</application>
</manifest>
вот мой отладчик logcat
2020-03-20 16:27:11.094 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: stopped(false) old=false
2020-03-20 16:27:11.106 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-03-20 16:27:11.107 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: prepareNavigationBarInfo() DecorView@8cab16b[MainActivity]
2020-03-20 16:27:11.107 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: getNavigationBarColor() -855310
2020-03-20 16:27:11.108 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: prepareNavigationBarInfo() DecorView@8cab16b[MainActivity]
2020-03-20 16:27:11.108 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: getNavigationBarColor() -855310
2020-03-20 16:27:11.108 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: startInputInner - Id : 0
2020-03-20 16:27:11.108 26522-26522/com.spotech.placepickerdemo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2020-03-20 16:27:11.111 26522-26522/com.spotech.placepickerdemo D/InputTransport: Input channel constructed: fd=72
2020-03-20 16:28:10.858 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: ViewPostIme pointer 0
2020-03-20 16:28:10.966 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: ViewPostIme pointer 1
2020-03-20 16:28:11.421 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: ViewPostIme pointer 0
2020-03-20 16:28:11.535 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: ViewPostIme pointer 1
2020-03-20 16:28:11.581 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
2020-03-20 16:28:11.581 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: prepareNavigationBarInfo() DecorView@8cab16b[MainActivity]
2020-03-20 16:28:11.581 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: getNavigationBarColor() -855310
2020-03-20 16:28:11.748 26522-26522/com.spotech.placepickerdemo D/InputTransport: Input channel destroyed: fd=72
2020-03-20 16:28:12.195 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: stopped(false) old=false
2020-03-20 16:28:12.207 26522-26522/com.spotech.placepickerdemo D/ViewRootImpl@2abc404[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2020-03-20 16:28:12.207 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: prepareNavigationBarInfo() DecorView@8cab16b[MainActivity]
2020-03-20 16:28:12.207 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: getNavigationBarColor() -855310
2020-03-20 16:28:12.210 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: prepareNavigationBarInfo() DecorView@8cab16b[MainActivity]
2020-03-20 16:28:12.210 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: getNavigationBarColor() -855310
2020-03-20 16:28:12.210 26522-26522/com.spotech.placepickerdemo D/InputMethodManager: startInputInner - Id : 0
2020-03-20 16:28:12.210 26522-26522/com.spotech.placepickerdemo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2020-03-20 16:28:12.212 26522-26522/com.spotech.placepickerdemo D/InputTransport: Input channel constructed: fd=71