简体   繁体   中英

Kotlin service application icon

i tried to write a service on_boot_completed and it is working well. However, I tried to hide the application from app list. I tried

    val p = applicationContext.packageManager
    p.setComponentEnabledSetting(
        componentName,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP
    )

adding this in MainActivity.kt but my service does not work when I add this. I tried to remove launcher-main from manifest. All of them is resulting an issue like below.

have you declared this activity in your AndroidManifest.xml?

I declared it in my manifest. So my question is; how can I hide my app icon in app list?

just remove intent-filter declaration, these lines should be removed

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

leave only your Activity s tag without any content

<activity
    android:name="..."
    ... rest of params
    android:lastparam=""/>

note /> closing tag on end

edit: ofc this will hide your Activity s icon in launcher, but app itself still be visible in all apps list eg in system Settings, obviously with possibility for force stopping or uninstalling

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