samedi 19 août 2017

why else does not active in oncreate methode?

I'm trying to upgrade google play services manually, but always if statement activated. I test with two device.In first device that version of google play services smaller than 10 dialog show correctly, but in the second device that google play services has upgraded , the app crashes after execute.

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (checkPlayServices(ActivityMap.this) == true) {
        dialog.show();
    } else {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        shopOnMap();

        if (savedInstanceState != null) {
            mLastKnownLocation = savedInstanceState.getParcelable(KEY_LOCATION);
            mCameraPosition = savedInstanceState.getParcelable(KEY_CAMERA_POSITION);
        }

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */,
                        this /* OnConnectionFailedListener */)
                .addConnectionCallbacks(this)
                .addApi(LocationServices.API)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .build();
        mGoogleApiClient.connect();

    }
}


 public boolean checkPlayServices(Activity activity) {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ActivityMap.this);

        builder.setMessage("Do you want update Google play services?")
                .setTitle("Google Play Services"); 

        builder.setPositiveButton("ِDownload", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

                new DownloadNewVersion().execute();

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);
            }
        });
        dialog = builder.create();
    }
    return true;
}

Aucun commentaire:

Enregistrer un commentaire