0

I have a huge problem there, I am developing an application which starts after boot. It is easy to achieve by using BOOT_COMPLETED intent action, at least until Android 3.1, where all installed apps get "stopped" state (right?) and it has to be explicitly launched to register all BroadcastReceivers. I therefore added an activity to let my app launch (Since the rest is based on a service, no icon in launcher) for the first time and register receivers. The weird thing that happened is that on 2.2 it works perfectly, while on Android 4.0 and 4.1 (and I guess all above 3.1) I gets error "Unable to start service intent {...} not found". I think it's weird my cmp = smth/.service and not smth.service. Could You please explain me the difference in those systems related to this problem?

My manifest (application part, rest of it is not relevant):

<application android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
  <receiver android:name=".ReceiverCall" android:exported="false" android:enabled="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.intent.action.SCREEN_ON" />
            <action android:name="android.intent.action.SCREEN_OFF" />
            <action android:name="com.android.ondeath" />
        </intent-filter>
</receiver>
  <service android:name="TheService" android:label="@string/app_name" android:exported="false" android:enabled="true" />
  <activity android:name=".Main"
            android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
  </activity>
</application>

and also the receiver:

public class ReceiverCall extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    if(TheService.running() == false)
    {
    Log.d("Service", "ReceiverCall onReceive()");
    context.startService(new Intent(context, TheService.class));
    }
}
}

My activity just starts, has no layout, it runs onCreate which only has "finish()" within itself.

Thanks for any suggestions that could lead me to the right solution :)

@EDIT

I hope this is what You meant.

09-28 16:26:09.509: E/Trace(599): error opening trace file: No such file or directory (2)
09-28 16:26:09.639: I/ActivityThread(599): Pub com.android.calendar:     com.android.providers.calendar.CalendarProvider2
09-28 16:26:09.869: D/ExchangeService(550): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
09-28 16:26:09.929: D/dalvikvm(182): WAIT_FOR_CONCURRENT_GC blocked 0ms
09-28 16:26:10.140: D/dalvikvm(182): GC_EXPLICIT freed 544K, 13% free 11241K/12871K, paused 23ms+38ms, total 214ms
09-28 16:26:10.259: D/dalvikvm(615): Not late-enabling CheckJNI (already on)
09-28 16:26:10.289: I/ActivityManager(182): Start proc co.appdemo for broadcast co.appdemo/.ReceiverCall: pid=615 uid=10044 gids={3003, 1015, 1028}
09-28 16:26:10.629: E/Trace(615): error opening trace file: No such file or directory (2)
09-28 16:26:10.729: D/Service(615): running()
09-28 16:26:10.729: D/Service(615): ReceiverCall onReceive()
09-28 16:26:10.749: W/ActivityManager(182): Unable to start service Intent { cmp=co.appdemo/.TheService }: not found
09-28 16:26:11.079: D/dalvikvm(294): GREF has increased to 201
Ziker
  • 141
  • 4
  • 20
  • Please post the actual stack trace, with the full error message. Also, I will be rather surprised if your `` works properly when it is not exported, as third-party apps cannot send it broadcasts. – CommonsWare Sep 28 '13 at 16:12
  • Alright, is that what You need? The receiver works correctly since all broadcasts are sent by system (right?) and the last one is sent from inside this package (and unused anyway). – Ziker Sep 28 '13 at 16:32
  • "The receiver works correctly since all broadcasts are sent by system (right?)" -- I am not aware that the system can send broadcasts to non-exported receivers. Is the `startService()` call that is failing the one you show in your activity? – CommonsWare Sep 28 '13 at 16:36
  • I don't call it from my activity, I call it from the BroadcastReceiver posted in the question and yes, this fails. Regardint broadcasts, I mean BOOT_COMPLETED, USER_PRESENT, etc. are system broadcasts, aren't they? I have it false, but it still receives the broadcast, what can bee seen in that log. Maybe I should make my service exported? @EDIT (After changing receiver `exported` to `true` nothing has changed, same with service) – Ziker Sep 28 '13 at 16:44
  • Nope. What you have isn't adding up. – CommonsWare Sep 29 '13 at 11:19
  • Maybe http://stackoverflow.com/questions/29081414/why-wont-this-broadcast-receiver-work-in-lollipop#comment58423396_29274695 helps. Try again removing `exported=false`. – OneWorld Feb 12 '16 at 09:34

2 Answers2

0

Instead of

<service android:name="TheService"

you may want to have

<service android:name=".TheService"
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

I really don't think that this error relevent with your service or receiver. Becuase it says this class cannot be found: com.android.providers.calendar.CalendarProvider2

So probably you are using some third-party library or something, is that right? If it is, then it might be a problem relevent how you implement it?

If it is a jar, i would recommend you to go properties > Java Build Path and there if your jar has no tick, put it on and clean your project run again.

yahya
  • 4,810
  • 3
  • 41
  • 58
  • nope, it's a part of the log from other application, the error is with co.appdemo. – Ziker Sep 28 '13 at 16:41
  • So your "TheService" class is right in co.appdemo.TheService position right ? And your package name is "co.appdemo" right? – yahya Sep 28 '13 at 16:44
  • Yes, like I said it works perfectly on Android 2.2, so I can't find the reason it would not work correctly on other version. – Ziker Sep 28 '13 at 16:47