1

Having seen the questions about activities with no GUI here, here and here. In addition, these answer are rather old, I don't know if they're still relevant.

I want to create an app for which the only user interaction is a quick tile.

I understood there can't be no activity at all, so I have a blank activity with no display using @android:style/Theme.NoDisplay

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoDisplay">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

<service
    android:name=".AdaptativeSleepTile"
    android:icon="@drawable/ic_launcher_background">
</service>

But the app appears in my app list (with nothing happening when I click it, logically), which is not what is written in the comments of this answer.

I can't remove the line <category android:name="android.intent.category.LAUNCHER"/> otherwise I get the error message

Could not identify launch activity: Default Activity not found
Error while Launching activity

So what should I do to have a service for which the only user interaction is the quick tile? (Same question would also apply for no interaction at all, or only widget I guess)

Using Android Studio 4 and Sdk 29

sayanel
  • 301
  • 2
  • 12

1 Answers1

1

I want to create an app for which the only user interaction is a quick tile.

That may or may not be practical. Since Android 3.1, apps are installed in a "stopped state", and it takes an explicit Intent to move them out of the stopped state and allow them to run. Normally, that comes from the user tapping on an icon in a launcher to run your MAIN/LAUNCHER activity.

It is possible that simply having a TileService available in the manifest is enough to get you listed in the notification shade, and the act of adding the tile will be enough to move your app out of the stopped state. However, I certainly cannot guarantee that, and it would not surprise me if this does not work.

Also, please bear in mind that you may need an activity for other reasons:

  • To display your terms of service
  • To display your privacy policy
  • To provide access to tech support
  • To allow for configuration of the app
  • And so on

But the app appears in my app list (with nothing happening when I click it, logically), which is not what is written in the comments of this answer.

If you mean the first comment, that is simply wrong, as is pointed out by other comments on that answer.

I can't remove the line otherwise I get the error message

I assume that you are getting that from Android Studio. You will need to change your run configuration to not try starting an activity.

Same question would also apply for no interaction at all

Fortunately, there is no solution for that. Malware authors think that totally invisible apps are wonderful, and Android takes steps to prevent such apps from being able to work. And, this is why I would not be surprised if you need an activity for your TileService.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for the answer, for this specific usage I'm developing for myself so I don't think a terms of services will be useful... I didn't thought about the security issues though. But the phone came with many pre-installed services and not all of them had icons in the drawer, for example build-in torchlight or cast are only accessible through tile. Here I wanted the tile perform an action like showing a fortune. Could you explain me what I should do to change my run configuration? – sayanel Jan 05 '21 at 14:16
  • @sayanel: "Could you explain me what I should do to change my run configuration?" -- go to Run > Edit Configurations in the Android Studio main menu. Choose your run configuration (e.g., `app`) in the list. Change the value of "Launch Options" from "Default Activity" to something else, probably "Nothing". Then, when you run the app from Studio, the APK will be installed, but nothing else will happen. – CommonsWare Jan 05 '21 at 14:29
  • Thanks that worked: I set "Launch option" to `Nothing` and commented removed `` : my app now doesn't have a drawer entry, only a tile – sayanel Jan 05 '21 at 14:37
  • Regarding the stopped/start state, I use the tile onClick() method, which I think will always be available – sayanel Jan 05 '21 at 14:54