You can simply use the Package Manager's System features to check if the device has a gyroscope in it:
PackageManager packageManager = getPackageManager();
boolean gyroExists = packageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE);
Your current code may not work on some devices as the sensor name is not guaranteed to contain Gyroscope
in it.