0

I'm trying to use FCM to send myself some monitoring data. I already implemented a working solution based on the quick starts but because I just want to provide a way to receive notifications, my app is completely useless. I know I can just remove

<activity android:name=".Notifications" >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

From the manifest to get an app without Launcher, like a background service. Doing so seems to desactivate FCM.

The real question is :

Can I use FCM without activity, by just implementing services ?

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
Nicolas Gomez
  • 133
  • 3
  • 8
  • 1
    How do you plan on registering for FCM? Nothing in your app will run until the user runs your launcher activity or something else uses an explicit `Intent` to invoke a component in your app. – CommonsWare Apr 10 '18 at 12:12

1 Answers1

1

You need to start your app at least one time in order to start a Service or register a BroadcastReceiver. You can find more about this here:

Android application as a service without activity

Note that after starting, you can just create a BroadcastReceiver which detects a device startup, then starts a Service and then use FCM.

gi097
  • 7,313
  • 3
  • 27
  • 49
  • 1
    Isn't starting a service power consumming ? let's say that I manage to start the service only once (for exemple when installing the App using something like adb) does FCM will still work after a phone restart ? If I must start a service at each phone reboot can I launch a one shot service (initialize FCM, register to topics and exit) ? Will do some experiments on my own anyway :) thanks for your answer – Nicolas Gomez Apr 10 '18 at 12:52
  • Yes that is possible. It depends if you make the `Service` `STICKY` or not. – gi097 Apr 10 '18 at 13:03