代码之家  ›  专栏  ›  技术社区  ›  Mokus

无法启动服务

  •  0
  • Mokus  · 技术社区  · 11 年前

    我正在尝试启动服务

    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 回复  |  直到 11 年前
        1
  •  2
  •   Dave Morrissey    11 年前

    代替 startActivity(gattServiceIntent); 具有 startService(gattServiceIntent); .

        2
  •  0
  •   VVB    11 年前

    试试看:

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