سؤال

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);
هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top