简体   繁体   中英

Android service not starting with a warninig

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

如果要向服务发送隐式意图 - 请在清单中更改为android:exported =“true”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM