Android 服务级别不工作

Android 服务级别不工作,android,Android,我的服务类没有调用,并且没有错误、崩溃报告或异常!调用服务之前和之后的线路都在工作,我还使用isMyServiceRunning方法检查了它是否在工作 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVi

我的服务类没有调用,并且没有错误、崩溃报告或异常!调用服务之前和之后的线路都在工作,我还使用isMyServiceRunning方法检查了它是否在工作

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     Intent i = new Intent(this, MyService.class);
    startService(i);
    Toast.makeText(this,"to check if this is working",Toast.LENGTH_LONG).show();
   }

}
服务类别:

public class MyService extends Service implements SensorEventListener {

private SensorManager mSensorManager;
private Sensor mSensor;

double ax, ay, az;

@Override
public void onCreate() {
    super.onCreate();

    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);


    if (mSensor != null) {
        mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
    } else {

        stopSelf();
    }
}

@Override
public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

       ax = event.values[0]; 
       bx = event.values[1];
       cx = event.values[2];
    }
}

@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
}
}
清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.star.sproject">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <service
        android:name=".MyService"
        android:enabled="false"
        android:exported="false"></service>
</application>


求求你,救命

尝试在manifest.xml中将服务声明的属性
android:enabled
设置为
true
,否则无法实例化服务

这样做

    <service
        android:name=".MyService"
        android:enabled="true"
        android:exported="true">
   </service>

enabled=“false”表示服务未启用非常感谢!欢迎您。:)如果答案解决了你的问题,请接受。