As stated above, check if you have an internet connection. !!
private void CheckConnection() { ConnectivityManager cm = (ConnectivityManager) getApplicationContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) answer="You are connected to a WiFi Network"; System.out.println(answer); if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) answer="You are connected to a Mobile Network"; } else answer = "No internet Connectivity"; Toast.makeText(getApplicationContext(), answer, Toast.LENGTH_LONG).show(); }
In the manifest file add
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:name="android.hardware.location.gps" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
if in action
@Override protected void onStart() { super.onStart(); if (!googleApiClient.isConnecting() || !googleApiClient.isConnected()) { googleApiClient.connect(); } }
and in function oncreate
//Initializing googleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); googleApiClient.connect();
in the Service class, do the following in Oncreate .
user6602265
source share