Process: Unable to start service com.google.android.gms.checkin.CheckinService with Intent

Posted by AndyRoid on Stack Overflow See other posts from Stack Overflow or by AndyRoid
Published on 2014-06-09T03:09:53Z Indexed on 2014/06/09 3:25 UTC
Read the original article Hit count: 621

I'm trying to build a Google map application but keep receiving this in my LogCat. I have all the permissions and meta-data set in my manifest, but am still dumbfounded by this error. Have looked everywhere on SO for this specific error but found nothing relating to com.google.android.gms.checkin

A little bit about my structural hierarchy. MainActivity extends ActionBarActivity with three tabs underneath actionbar. Each tab has it's own fragment. On the gMapFragment I create a GPSTrack object from my GPSTrack class which extends Service and implements LocationListener.

The problem is that when I start the application I get this message:

enter image description here

I have all my libraries imported properly and I even added the google-play-services.jar into my libs folder. I also installed Google Play Services APKs through CMD onto my emulator.

Furthermore the LocationManager lm = = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); in my GPSTrack class always returns null.

Why is this and how can I fix these issues? Would appreciate an explanation along with solution too, I want to understand what's going on here.

==============

Code:

gMapFragment.java

public class gMapFragment extends SupportMapFragment {

private final String TAG = "gMapFragment";

private GoogleMap mMap;
protected SupportMapFragment mapFrag;

private Context mContext = getActivity();

private static View view;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    if (view != null) {
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
    }
    try {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.fragment_map, container, false);
        setupGoogleMap();
    } catch (Exception e) {
        /*
         * Map already there , just return as view
         */
    }
    return view;
}

private void setupGoogleMap() {
    mapFrag = (SupportMapFragment) getFragmentManager().findFragmentById(
            R.id.mapView);
    if (mapFrag == null) {
        FragmentManager fragManager = getFragmentManager();
        FragmentTransaction fragTransaction = fragManager
                .beginTransaction();
        mapFrag = SupportMapFragment.newInstance();
        fragTransaction.replace(R.id.mapView, mapFrag).commit();
    }
    if (mapFrag != null) {
        mMap = mapFrag.getMap();
        if (mMap != null) {
            setupMap();
            mMap.setOnMapClickListener(new OnMapClickListener() {

                @Override
                public void onMapClick(LatLng point) {
                    // TODO your click stuff on map

                }

            });

        }
    }
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    Log.d("Attach", "on attach");
}

@Override
public void onDetach() {
    super.onDetach();
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public void onResume() {
    super.onResume();
}

@Override
public void onPause() {
    super.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
}

private void setupMap() {

    GPSTrack gps = new GPSTrack(mContext);

    // Enable MyLocation layer of google map
    mMap.setMyLocationEnabled(true);
    Log.d(TAG, "MyLocation enabled");
    // Set Map type
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    // Grab current location
    **ERROR HERE/Returns Null** Location location = gps.getLocation();
    Log.d(TAG, "Grabbing location...");

    if (location != null) {
        Log.d(TAG, "location != null");
        // Grab Latitude and Longitude
         double latitude = location.getLatitude();
         double longitude = location.getLongitude();
         Log.d(TAG, "Getting lat, long..");
        // Initialize LatLng object
        LatLng latLng = new LatLng(latitude, longitude);
        Log.d(TAG, "LatLng initialized");
        // Show current location on google map
         mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

        // Zoom in on google map
        mMap.animateCamera(CameraUpdateFactory.zoomTo(20));
        mMap.addMarker(new MarkerOptions().position(
                new LatLng(latitude, longitude)).title("You are here."));

    } else {
        gps.showSettingsAlert();
    }
}
}

GPSTrack.java

public class GPSTrack extends Service implements LocationListener{

private final Context mContext;

private boolean isGPSEnabled = false;

//See if network is connected to internet
private boolean isNetworkEnabled = false;

//See if you can grab the location
private boolean canGetLocation = false;

protected Location location = null;
protected double latitude;
protected double longitude;

private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 10; //10 Meters

private static final long MINIMUM_TIME_CHANGE_FOR_UPDATES = 1000 * 60 * 1; //1 minute

protected LocationManager locationManager;


public GPSTrack(Context context) {
    this.mContext = context;
    getLocation();
}

public Location getLocation() {
    try {
        //Setup locationManager for controlling location services
        **ERROR HERE/Return Null** locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

        //See if GPS is enabled
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        //See if Network is connected to the internet or carrier service
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            Toast.makeText(getApplicationContext(), "No Network Provider Available", Toast.LENGTH_SHORT).show();
        } else {
            this.canGetLocation = true;
            if (isNetworkEnabled) {
                locationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER, 
                        MINIMUM_TIME_CHANGE_FOR_UPDATES, 
                        MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, 
                        this);
                Log.d("GPS", "GPS Enabled");

                if (locationManager != null) {
                    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                    if (location != null) {
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();
                    }

                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}

public void stopUsingGPS() {
    if (locationManager != null) {
        locationManager.removeUpdates(GPSTrack.this);
    }
}

public double getLatitude() {
    if (location != null) {
        latitude = location.getLatitude();
    }

    return latitude;
}

public double getLongitude() {
    if (location != null) {
        longitude = location.getLongitude();
    }

    return longitude;
}

public boolean canGetLocation() {
    return this.canGetLocation;
}
    public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    //AlertDialog title
    alertDialog.setTitle("GPS Settings");

    //AlertDialog message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to Settings?");

    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                mContext.startActivity(i);
            }
        });
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.cancel();
            }
        });
    alertDialog.show();

}

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
}

logcat

06-08 22:35:03.441: E/AndroidRuntime(1370): FATAL EXCEPTION: main
06-08 22:35:03.441: E/AndroidRuntime(1370): Process: com.google.android.gms, PID: 1370
06-08 22:35:03.441: E/AndroidRuntime(1370): java.lang.RuntimeException: Unable to start service com.google.android.gms.checkin.CheckinService@b1094e48 with Intent { cmp=com.google.android.gms/.checkin.CheckinService }: java.lang.SecurityException: attempting to read gservices without permission: Neither user 10053 nor current process has com.google.android.providers.gsf.permission.READ_GSERVICES.
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2719)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ActivityThread.access$2100(ActivityThread.java:135)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.os.Handler.dispatchMessage(Handler.java:102)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.os.Looper.loop(Looper.java:136)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ActivityThread.main(ActivityThread.java:5017)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at java.lang.reflect.Method.invokeNative(Native Method)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at java.lang.reflect.Method.invoke(Method.java:515)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at dalvik.system.NativeStart.main(Native Method)
06-08 22:35:03.441: E/AndroidRuntime(1370): Caused by: java.lang.SecurityException: attempting to read gservices without permission: Neither user 10053 nor current process has com.google.android.providers.gsf.permission.READ_GSERVICES.
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ContextImpl.enforce(ContextImpl.java:1685)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1714)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:572)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at imq.c(SourceFile:107)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at imq.a(SourceFile:121)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at imq.a(SourceFile:227)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at bwq.c(SourceFile:166)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at com.google.android.gms.checkin.CheckinService.a(SourceFile:237)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at com.google.android.gms.checkin.CheckinService.onStartCommand(SourceFile:211)
06-08 22:35:03.441: E/AndroidRuntime(1370):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2702)

AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />

<uses-permission android:name="com.curio.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.app.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AI........................" />
</application>

© Stack Overflow or respective owner

Related posts about java

Related posts about android