服务无法在Android Nexus Player中启动?

时间:2017-03-17 08:04:42

标签: nexus-player

我正在为Android Nexus Player(电视)开发应用。我试图按下按钮启动服务,但服务没有启动。我错过了什么吗?这项服务正在Android平板电脑完美。但不是Nexus播放器(电视盒)。

按钮上的代码点击:

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);
    }

1 个答案:

答案 0 :(得分: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;
    }