无法启动该服务

时间:2014-07-14 19:01:42

标签: android android-intent

我正在尝试启动服务

Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
        bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
        startActivity(gattServiceIntent);

但是我收到以下消息

07-14 20:58:13.296: E/AndroidRuntime(21311): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.rcfun.blecar/com.rcfun.blecar.util.BluetoothLeService}; have you declared this activity in your AndroidManifest.xml?

我试图声明如下

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

    <service
        android:name="com.rcfun.blecar.util.BluetoothLeService"
        android:enabled="true">            
    </service>  

但是这两个声明都给出了与我上面提到的相同的错误。

2 个答案:

答案 0 :(得分:2)

startActivity(gattServiceIntent);替换为startService(gattServiceIntent);

答案 1 :(得分:0)

试试这个:

bindService(new Intent(this,BluetoothLeService.class),mServiceConnection,Context.BIND_AUTO_CREATE);