在 Android Studio 中进行 运行 AVD 时应用崩溃。我 运行 虚拟设备像素 5x API 27
App is crashing while running AVD in Android Studio. I am running on virtual device pixel 5x with API 27
当我尝试创建 FusedLocationApi 的实例时,它无法被识别。它是红色的。它没有导入任何 类。在我看来 Gradle Build App 中可能存在一些问题。请检查一下。
这是我的 MapActivity.java 文件
package com.matt.mapapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleMap mMap;
private LocationRequest locationRequest;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
String[] permissions,
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
private synchronized void buildGoogleApiClient(){
client = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
client.connect();
}
@Override
public void onLocationChanged(Location location) {
locationRequest = new LocationRequest();
locationRequest.setInterval(1000);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
LocationRequest.FusedLocationApi.requestlocationUpdates(client, locationRequest, this);
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
}
这是我的构建 gradle(模块应用程序)文件。编译时似乎有一些问题,因为没有 compile
这样的命令
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.matt.mapapp"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation'com.android.support.test.espresso:espresso-core:2.2.2'
}
请检查并告诉我背后的原因。我正在观看有关如何创建基于地图的应用程序的视频教程,但突然间,当我到达使用 Fused Location Api 的位置时,我卡住了。教程中的构建 Gradle 代码与我的不同,所以我认为这可能是 FusedLocationApi 无法正常工作的原因。
在基于 Google 地图创建应用程序时,切勿使用虚拟设备,因为它在大多数情况下都会出错,而您应该使用 USB 调试连接到 android phones在。为此,您必须转到 phone 设置的有关部分,然后单击构建版本或构建编号 7 或它所说的成为开发人员所需的次数,而不是返回主菜单设置并从那里单击开发人员选项,您必须打开 USB 调试。现在您的 phone 会要求验证连接到 PC 单击接受并勾选记住我的选择。现在您将能够在所有列出的虚拟设备上方看到您的 phone,并且您将能够在您的 phone 中安装该应用程序。谢谢。
如果对您有帮助,请告诉我...
当我尝试创建 FusedLocationApi 的实例时,它无法被识别。它是红色的。它没有导入任何 类。在我看来 Gradle Build App 中可能存在一些问题。请检查一下。
这是我的 MapActivity.java 文件
package com.matt.mapapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener {
private GoogleMap mMap;
private LocationRequest locationRequest;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
String[] permissions,
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
private synchronized void buildGoogleApiClient(){
client = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
client.connect();
}
@Override
public void onLocationChanged(Location location) {
locationRequest = new LocationRequest();
locationRequest.setInterval(1000);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
LocationRequest.FusedLocationApi.requestlocationUpdates(client, locationRequest, this);
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
}
这是我的构建 gradle(模块应用程序)文件。编译时似乎有一些问题,因为没有 compile
这样的命令apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.matt.mapapp"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation'com.android.support.test.espresso:espresso-core:2.2.2'
}
请检查并告诉我背后的原因。我正在观看有关如何创建基于地图的应用程序的视频教程,但突然间,当我到达使用 Fused Location Api 的位置时,我卡住了。教程中的构建 Gradle 代码与我的不同,所以我认为这可能是 FusedLocationApi 无法正常工作的原因。
在基于 Google 地图创建应用程序时,切勿使用虚拟设备,因为它在大多数情况下都会出错,而您应该使用 USB 调试连接到 android phones在。为此,您必须转到 phone 设置的有关部分,然后单击构建版本或构建编号 7 或它所说的成为开发人员所需的次数,而不是返回主菜单设置并从那里单击开发人员选项,您必须打开 USB 调试。现在您的 phone 会要求验证连接到 PC 单击接受并勾选记住我的选择。现在您将能够在所有列出的虚拟设备上方看到您的 phone,并且您将能够在您的 phone 中安装该应用程序。谢谢。
如果对您有帮助,请告诉我...