1

Is it possible to create an app without any activities? Without a launcher icon and without the "open" button on Play Store? Like this one https://my.pcloud.com/publink/show?code=XZUi3I7Z6yNkHyuBISL5XynlYYI8SjEJcoMk

I only need it to create a background service. I've done some research and I haven't found anything about this. If you could just point me in a direction (or tell me it's not possible) it would be great! Cheers!

Zizico2
  • 45
  • 1
  • 5
  • I don't think your app can be notified after install to start a service and I don't think you can start any services until your app has been opened by the user. – Corey Ogburn May 23 '19 at 21:46
  • [Or maybe I'm wrong...](https://stackoverflow.com/questions/990217/how-to-start-service-only-android-app) – Corey Ogburn May 23 '19 at 21:49
  • My intent was to create a quick settings button. That would then toggle said service. And I know an app can create a quick settings button without being opened. And quick settings buttons are services in themselves so yeah... I think it's possible. I am sure a quick settings can be created without running the app. I've downloaded am app that does this. But it still has an activity as a place holder. – Zizico2 May 23 '19 at 21:49

1 Answers1

1

You said you didn't want to use a translucent Activity, but that seems to be the best way to do this:

1- In your Manifest, set the Activity theme to Theme.Translucent.NoTitleBar.

2- Don't bother with a layout for your Activity, and don't call setContentView().

3- In your Activity's onCreate(), start your Service with startService().

4- Exit the Activity with finish() once you've started the Service.

In other words, your Activity doesn't have to be visible; it can simply make sure your Service is running and then exit, which sounds like what you want.

how to hide luncher icon :

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" />
p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Hide open button couldn't be done , because we are talking about an application and not a google library

how to unhide icon :

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, com.apps.MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

IMPORTANT: It's somehow tricky if you need to do something with main activity in your app when it's hidden. you will face an ActivityNotFoundException. to make it work, you should unhide icon before doing anything to your main activity and hide it again after you are finished.

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38