package de.edotzlaff.schockwelle; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentActivity; import android.app.Dialog; import android.content.Intent; import android.hardware.Sensor; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; public class MainActivity extends FragmentActivity { private static final String TAG = "MainActivity"; private static final int ERROR_DIALOG_REQUEST = 9001; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (isServiceOK()){ init(); } } private void init(){ Button btnEarthquake = (Button) findViewById(R.id.btnEarthquake); btnEarthquake.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, EarthquakeMapsActivity.class); startActivity(intent); } }); Button btnSensor = (Button) findViewById(R.id.btnSensor); btnSensor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SensorMapsActivity.class); startActivity(intent); } }); } public boolean isServiceOK(){ Log.d(TAG, "isServicesOK(): checking google services version"); int available = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(MainActivity.this); if (available== ConnectionResult.SUCCESS){ Log.d(TAG,"isServicesOK: Google Play Services is working"); return true; } else if (GoogleApiAvailability.getInstance().isUserResolvableError(available)){ Log.d(TAG, "isServicesOK(): an error occured but we can fix it"); Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(MainActivity.this, available, ERROR_DIALOG_REQUEST); dialog.show(); } else { Toast.makeText(this, "You can`t make map request", Toast.LENGTH_SHORT).show(); } return false; } }