4

I have a service that supposed to upload photos in the background. But when I try to start it, it doesn't start. In the logcat I've noticed that I get a warning Implicit intents with startService are not safe : Intent { .....}. I've already tripled checked that the action string is the same in the manifest and what I'm starting with. My code :
manifest :

<service android:name=".photosupload.services.PhtosUploadService" 
  android:exported="false" android:process=":uploadPhotosServiceProcess">
  <intent-filter>
    <action android:name="com.yoovi.app.photosupload.services.action.START_UPLOAD" />
  </intent-filter>
</service>

starting service code :

  Intent i = new Intent(PhtosUploadService.ACTION_START_UPLOAD);
  i.putExtra(PhtosUploadService.ALBUM_ID, albumID);
  context.startService(i);
Youddh
  • 1,511
  • 4
  • 34
  • 51
RCB
  • 2,253
  • 2
  • 25
  • 49

2 Answers2

5

You need to understand implicit and explicit intents.

Explicit intent means you need to specify the exact class from which the intent will be serviced.

Your code should be similar to

    Intent i = new Intent();  
i.setClass(this, photosupload.services.PhtosUploadService.class);
Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • Why can't I start it implicitly ? I do the exact same thing in my another app and it works perfectly – RCB Jan 08 '14 at 06:36
  • 1
    You can but android gives a warning if you are using startservice. "Implicit intents with startService are not safe" – Madhur Ahuja Jan 08 '14 at 06:37
  • But it doesn't start, I have breakpoints in the `onCreate` and in on `onStartCommand` but it never gets there – RCB Jan 08 '14 at 06:39
  • 1
    That's a different issue, what is the value of variable ACTION_START_UPLOAD – Madhur Ahuja Jan 08 '14 at 06:46
  • O.k. I've found something, If I don't try to start it in a different process, it works. What am I doing wrong? – RCB Jan 08 '14 at 06:52
  • Why do you want to run in a different process? – Madhur Ahuja Jan 08 '14 at 06:55
  • It's a large upload, It'll probably end after the user stops using the app. Now I've noticed that it does start, just the eclipse debugger wont go there – RCB Jan 08 '14 at 06:58
  • 1
    why not use intentservice ? http://developer.android.com/reference/android/app/IntentService.html – Madhur Ahuja Jan 08 '14 at 06:59
  • @MadhurAhuja, I am facing same issue but the same thing working fine in another app, i can't convert it into explicit intent. Can you please suggest me what to do with this. Thanks in advance! – Bipin Vayalu Feb 28 '14 at 20:39
0

If you want to send implicit intent to a service - Please Change to android:exported="true" in manifest.

Udi Reshef
  • 1,083
  • 1
  • 11
  • 14