谷歌地图应用程序崩溃在棒棒糖机器人

时间:2015-10-21 05:12:44

标签: android google-maps crash android-5.0-lollipop

我在我的Android应用程序中实现Google map API v2。该应用程序适用于所有设备,但不适用于棒棒糖设备。应用程序在棒棒糖中崩溃。我确实在寻找这个问题,但没有得到合理的解决方案。如果有人知道这个问题,请帮帮我。我会非常感激

2 个答案:

答案 0 :(得分:2)

可能是你想通过这个位置来获取位置 LocationManager课程。这种方式完美适用于preLollipop设备。但在棒棒糖中,它不起作用。现在再次谷歌已经发布了一个新的API,但他们没有正确更新文档。这里有一个位置获取演示代码,它将使您使用新的/最新的位置服务API在一定时间间隔后获取位置对象。

import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

/**
 * Created by skarim on 10/29/15.
 */
public class GetLocationAfterCertainInterval extends Activity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener ,
        LocationListener {
    GoogleApiClient apiClient=null;
    LocationRequest mLocationRequest=null;
    private int locationInterval,fastedInterval;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Initialize Your View here.
        setLocationLocationRequest();
    }

    @Override
    public void onDestroy() {
        // Your need of location update is done. So you have to stop the apiClient.
        super.onDestroy();
        this.apiClient.disconnect();
    }


    private void setLocationLocationRequest() {

        try {
            apiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();

            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(29000);
            mLocationRequest.setFastestInterval(5000);
            mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            apiClient.connect();

        }catch (Exception e){
            Log.d("LS", e.getMessage() == null ? "" : e.getMessage());
        }

    }
    @Override
    public void onConnected(Bundle bundle) {
        // Your API Client is connected. So can request for updates
        LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, mLocationRequest, this);
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onLocationChanged(Location location) {
        // After your desired interval This api will give you the Location Object.

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }


}

有关此API的详细信息,请参阅this Developer Link

我的相关Answer is here

抱歉英文不好。谢谢

答案 1 :(得分:0)

尝试使用Android Studio生成Google地图活动。