0

My aim is to start a service, that is added via .jar file as an android plugin in Unity3D. In this thread I found out how to launch it, I can finnaly get to native code. But I've encountered the following problem in the log:

07-14 15:02:23.965: W/ActivityManager(444): Unable to start service Intent { cmp=net.calipssoone.bnh/com.activitychecker.adservice.CheckService } U=0: not found

I googled and found out that the problem is in the manifest, but couldn't figure out what am I doing wrong. Here's how the service is declared in the manifest:

  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<service android:name="com.activitychecker.adservice.CheckService"/>
<receiver android:name="com.activitychecker.adservice.StartReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
    <action android:name="CheckService" />
  </intent-filter>
</receiver>

Its package name in Java is actually the same: com.activitychecker.adservice

StartReceiver class:

    public class StartReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {}
}

CheckService class:

public class CheckService extends Service {
    public void onCreate(){}
    public long getCurrentTime(){}
    public void loadInfo(){}
    public int onStartCommand(Intent intent, int flags, int startId){}
    public void onDestroy() {}
    public IBinder onBind(Intent intent) {}
    public class MyThread extends Thread { 
        public void run() {}
        public void cancel() {}
        public boolean check(String bundle){}
    }
    private class ScreenBroadcastReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {}
    }
}

UPD: I've changed my manifset from:

<service android:name="com.activitychecker.adservice.CheckService"/>

To:

<service android:name="com.activitychecker.adservice.CheckService"></service>

And the log error changed to:

07-14 17:46:13.455: W/ActivityManager(444): Unable to start service Intent { act=com.activitychecker.adservice.CheckService } U=0: not found
Community
  • 1
  • 1
Sam Stone
  • 477
  • 2
  • 10
  • 33
  • It would be good if you post the CheckService and StartReceiver class. I don't want to see the code inside them. Just the blueprint of it and the functions in it. – Programmer Jul 14 '16 at 11:45
  • have you tried [this](http://stackoverflow.com/a/3439838/4366237)? – Umair M Jul 14 '16 at 11:51
  • I've updated the question code, @Programmer – Sam Stone Jul 14 '16 at 12:46
  • @UmairM If the point of that answer is to call intent via string, I've just tried it, without any success. I do not have any "remote" attributes in my manifest. Service attribute is inside the application tag and has full package path, because it is in another package. – Sam Stone Jul 14 '16 at 13:12
  • I did experiment today and I think I found your problem. Not not really sure but is this problem solved? – Programmer Jul 21 '16 at 12:53
  • @Programmer the issue is not yet solved. – Sam Stone Jul 22 '16 at 08:22
  • Ok. See my answer. Comment on the answer if that didn't work for you. I did experiment and got it working like that. – Programmer Jul 23 '16 at 06:01

2 Answers2

2

I got the-same exception when I tried to start service with Intent. It worked when I used Context. So replace the code from your last question with the one below that uses Context instead of Intent:

Java:

public final class StatusCheckStarter {
    static Context myContext;
    // Called From C# to get the Context Instance
    public static void receiveContextInstance(Context tempContext) {
        myContext = tempContext;
    }
    public static void StartCheckerService()
    {
        myContext.startService(new Intent(myContext, CheckService.class));
    }
}

C#:

AndroidJavaClass unityClass;
AndroidJavaObject unityActivity;
AndroidJavaObject unityContext;
AndroidJavaClass customClass;

void Start()
{
    //Replace with your full package name
    sendActivityReference("com.example.StatusCheckStarter");

    //Now, start service
    startService();
}

void sendActivityReference(string packageName)
{
    unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    unityActivity = unityClass.GetStatic<AndroidJavaObject>("currentActivity");
    unityContext = unityActivity.Call<AndroidJavaObject>("getApplicationContext");

    customClass = new AndroidJavaClass(packageName);
    customClass.CallStatic("receiveContextInstance", unityContext);
}

void startService()
{
    customClass.CallStatic("StartCheckerService");
}

Comment if there is any problem.

Programmer
  • 121,791
  • 22
  • 236
  • 328
0

I´ve found the solution copping the manifest directly to the assets/android folder.

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
 android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application
  android:theme="@style/UnityThemeSelector"
  android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:debuggable="true">
        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
        <service android:name="com.addcomponent.unitynativeplugin.GeoLocation"/>
    </application>
</manifest>