Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RemoteService无法启动服务意图_Android_Android Intent_Android Service - Fatal编程技术网

Android RemoteService无法启动服务意图

Android RemoteService无法启动服务意图,android,android-intent,android-service,Android,Android Intent,Android Service,我正在尝试构建一个远程服务,我可以绑定到经常使用和创建的活动。我认为这是处理我正在努力完成的事情的最好方法。不过,我一直在犯这个错误 无法启动服务意图{act=com.services.oversedservice}U=0:未找到 我想我的舱单可能有问题?但我看不到什么,我的清单将在下面相关代码的底部 以下是活动中我的onCreate()中的调用: // TESTING SERVICE IMPLMENTATION TODO Intent serviceIntent = new Intent("c

我正在尝试构建一个远程服务,我可以绑定到经常使用和创建的活动。我认为这是处理我正在努力完成的事情的最好方法。不过,我一直在犯这个错误

无法启动服务意图{act=com.services.oversedservice}U=0:未找到

我想我的舱单可能有问题?但我看不到什么,我的清单将在下面相关代码的底部

以下是活动中我的onCreate()中的调用:

// TESTING SERVICE IMPLMENTATION TODO
Intent serviceIntent = new Intent("com.services.OverheadService");
boolean ok = this.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
Log.v("ok", String.valueOf(ok));
以下是连接方法:

/** SERVICE IMPLEMENTATION TESTING **/
    private ServiceConnection mServiceConnection = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            // get instance of the aidl binder
            mRemoteService = IRemoteService.Stub.asInterface(service);
            try {
                String message = mRemoteService.sayHello("Mina");
                Log.v("message", message);
            } catch (RemoteException e) {
                Log.e("RemoteException", e.toString());
            }

        }
    };
这是服务类:

package com.services;

import com.services.IRemoteService.Stub;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

public class OverheadService extends Service {

    @Override
    public IBinder onBind(Intent arg0) {
        return mBinder;
    }

    // implementation of the aidl interface
    private final IRemoteService.Stub mBinder = new Stub() {

        @Override
        public String sayHello(String message) throws RemoteException {
            return "Hello " + message;
        }
    };

}
正在设置服务的AndroidManifest:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <service
            android:name="com.services.OverheadService"
            android:enabled="true"
            android:icon="@drawable/failed_load" >

            <!--
            intent-filter>
                <action android:name="com.cdkdevelopment.BaseActivity" />
            </intent-filter>
            -->
        </service>

我找到了解决方案,它在onCreate中改变了这一点

Intent serviceIntent = new Intent(this, OverheadService.class);
boolean ok = this.getApplicationContext().bindService(serviceIntent,
    mServiceConnection, Context.BIND_AUTO_CREATE);
Log.v("ok", String.valueOf(ok));
也许这会有帮助