0

我正在为 Android Nexus Player(TV) 开发应用程序。我试图在单击按钮时启动服务,但服务没有启动。我错过了什么吗?该服务在安卓平板电脑上完美运行。但不在 Nexus Player(电视盒)上。

按钮点击代码:

Intent serviceIntent = new Intent(this, MyService.class);
ComponentName componentName = startService(serviceIntent);

if(componentName == null)
    showLogText("Service does not start"); 

清单声明

<service android:name="com.hdmi.MyService"/>

onStartCommand 是这样实现的

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        systemAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if(acceptThread != null && acceptThread.isAlive())
            acceptThread.cancel();
        else {
            acceptThread = new AcceptThread();
            acceptThread.start();
            Log.i("Server", "Starting");
        }

        return super.onStartCommand(intent, flags, startId);
    }
4

1 回答 1

1

尝试这个

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        systemAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        if(acceptThread != null && acceptThread.isAlive())
            acceptThread.cancel();
        else {
            acceptThread = new AcceptThread();
            acceptThread.start();
            Log.i("Server", "Starting");
        }

        //return super.onStartCommand(intent, flags, startId);
        return Service.START_STICKY;
    }
于 2017-03-17T09:25:23.343 回答