Hiding Icon/App

Z80CPU

Member
Licensed User
Longtime User
Hello,

I searched on the keywords 'hidden icon' and while it did return results, not what i was seeking.

I have seen and this is what i desire, is when you download something like a license key app, they SW creator states that when you tele reboots, the icon for that app will be gone. And sure enough it is.



Example:

Before reboot:

App list shows:

10 apps with 10 icons

AFTER reboot:

9 app with 9 icons



this is what i am seeking as i am creating a service which will be launched from a normal app, thus there is no need for a icon for the service mod nor for it to be even listed to the EU.

any ideas? i though about a 'blank' icon, but the app itself would still show...so that is a no go...thought about non-text characters but i am not too sure how android would handle those...probably would puke on it...

so i am at a loss. on a pc, i can just set the 'hidden' attribute and be done with it.

i do not know what would happen if i 'attached' the service mod to the main app and then launched it that way...would it 'install' it the first time run? i think it would and then the icon/app showing problem would be right back...

NOTE: i am NOT talking about the notification icon..that's fine...it's the icon you see when you goto the apps list....

any help/ideas are appreciated!

thanks!

:)
 
Last edited:

Z80CPU

Member
Licensed User
Longtime User
Confirming...

Thank you for your reply.

To confirm that all i need to get a service with no icon and not listed in the 'apps' portion of the OS i put the following in the manifest:

AddReplacement(android.intent.action.MAIN, unused_action)

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


these will accomplish the task at hand?

thanks!

:)
 
Upvote 0

gudino jose luis

Active Member
Licensed User
Longtime User
Hello everyone.
this feature is still current? from version 4 to back, this could be done
but now I think it's not possible.

my question in particular, may or may not hide the application icon,
revice and the great majorities of responses that are in the forum and I did not work

now I have a big problem because I sold a customer an application that was hidden, were one phone with version 4 this week update all their phones and now my application is useless.

what can I do

Thank you for your help.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Could you compile your app with the standard 'Main activity has the launcher Intent' and let the user run your app for a first time.
Then disable that launcher Intent after the user has run your app at least once?

You'll need to use Reflector/JavaObject or inline java to disable the launcher Intent.
Reflector example here: https://www.b4x.com/android/forum/t...-icons-app-from-app-drawer.24723/#post-143255
JavaObject with inline java example here: https://www.b4x.com/android/forum/t...pp-loads-using-inline-java.52920/#post-332009
 
Upvote 0

gudino jose luis

Active Member
Licensed User
Longtime User
Thanks for the reply,
the program runs only the first time.
the next time you run the program will run only service
so I think it can work
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
But have you considered what Erel has said?

If the uses swipes the app from the 'recent apps' list then it will no longer receive any intents or broadcasts.

@Erel Will the service be startable if the user kills the app using the recent apps swipe and then the device is rebooted?
Will a reboot make the app startable?
 
Upvote 0

gudino jose luis

Active Member
Licensed User
Longtime User
thanks for your quick response

ok, I understand the problem and that is only the first time the application is executed.

if this is a big problem for me, I do not understand how android make these changes so abruptly, leaving programmers trouble with their customers because app that no longer be used.

there must be a solution!

p.d excuse my bad English
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

warwound

Expert
Licensed User
Longtime User
There's an interesting blog here: https://nayaneshguptetechstuff.word...w-more-about-stopped-state-of-an-application/

@Erel Will the service be startable if the user kills the app using the recent apps swipe and then the device is rebooted?
Will a reboot make the app startable?

To answer my own quesiton.
It looks as though the app will remain in it's 'stopped state' after a reboot - though i've not been able to confirm this.
So if your app user swipes your app from the recent apps list then your app will remain unstartable even after a reboot.

@gudino jose luis
You can compile your app and leave the Main Activity launcher Intent as it is - the default behavior.
After the user has run your app you can disable the Main Activity launcher Intent.
Now you will have what you want - your Service will be startable and no icon will show for your app in the launcher app.

But if the user kills your app - using the recent apps list or the Settings app - then your service will not be startable and your app user will have no way to make it startable.
A reboot of the device will not make your service startable.


You have a solution to hide the app icon from the launcher.
Now you need a solution for when/if the user kills your app and leaves it in an unstartable state.
 
Upvote 0

gudino jose luis

Active Member
Licensed User
Longtime User
There is an example of how to do this:
"After the user has run your app you can disable the Main Activity launcher Intent"

Thank.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Look at this example - adapted from the DynamicBroadcastReceiver example at https://www.b4x.com/android/forum/t...pp-loads-using-inline-java.52920/#post-332009

B4X:
#Region  Service Attributes 
	#StartAtBoot: True
	
#End Region

Sub Process_Globals

End Sub

Sub Service_Create
'		'	see http://developer.android.com/reference/android/content/pm/PackageManager.html
	
	'	This component is in its default enabled state (as specified in its manifest). 
	Dim ENABLED_STATE_DEFAULT As Int=0
	
	'	This component has been explicitly disabled, regardless of what it has specified in its manifest. 
	Dim ENABLED_STATE_DISABLED As Int=2
	
	'	This component has been explicitly enabled, regardless of what it has specified in its manifest. 
	Dim ENABLED_STATE_ENABLED As Int=1
	
	'	here you need to update the fully qualified name of the Main Activity
	Dim MAIN_ACTIVITY_FULLY_QUALIFIED_NAME As String="b4a.example.hideicon.main"
	
	Dim JavaObject1 As JavaObject
	JavaObject1.InitializeContext
	
	Dim EnabledState As Int=JavaObject1.RunMethod("getComponentEnabledSetting", Array As Object(MAIN_ACTIVITY_FULLY_QUALIFIED_NAME))
	
	Select EnabledState
		Case ENABLED_STATE_DEFAULT
			'	Main Activity is enabled by default (in the manifest)
			'	disable Main Activity
			JavaObject1.RunMethod("setComponentEnabledSetting", Array As Object(MAIN_ACTIVITY_FULLY_QUALIFIED_NAME, ENABLED_STATE_DISABLED))
		Case ENABLED_STATE_DISABLED
			'	do nothing
			'	this is the desired state to hide the app from the launcher
		Case ENABLED_STATE_ENABLED
			'	disable Main Activity
			JavaObject1.RunMethod("setComponentEnabledSetting", Array As Object(MAIN_ACTIVITY_FULLY_QUALIFIED_NAME, ENABLED_STATE_DISABLED))
		Case Else
			'	this case should never occur
			Log("unrecognised enabled state")
	End Select
	
	'	FYI you can re-enable the Main Activity in 2 ways
	
	'	you can restore the default enabled state - the default enabled state is enabled
	'	JavaObject1.RunMethod("setComponentEnabledSetting", Array As Object(MAIN_ACTIVITY_FULLY_QUALIFIED_NAME, ENABLED_STATE_DEFAULT))
	
	'	or you can explicitly set the enabled state to enabled
	'	JavaObject1.RunMethod("setComponentEnabledSetting", Array As Object(MAIN_ACTIVITY_FULLY_QUALIFIED_NAME, ENABLED_STATE_ENABLED))
	
End Sub

Sub Service_Start (StartingIntent As Intent)
	ToastMessageShow("Hide Launcher Icon : MyService started", False)
End Sub

Sub Service_Destroy

End Sub

#If JAVA

import android.content.ComponentName;
import android.content.pm.PackageManager;

public int getComponentEnabledSetting(String fullyQualifiedClassName){
	ComponentName componentName = new ComponentName(this, fullyQualifiedClassName);
	return this.getPackageManager().getComponentEnabledSetting(componentName);
}

public void setComponentEnabledSetting(String fullyQualifiedClassName, int enabledState){
	ComponentName componentName = new ComponentName(this, fullyQualifiedClassName);
	this.getPackageManager().setComponentEnabledSetting(componentName, enabledState, PackageManager.DONT_KILL_APP);
}

#End if

The Service starts and checks the 'enabled state' of the Main activity.
The Main activity contains the application's 'launcher intent'.
If the Main activity is enabled then it is disabled.

Tested here on my Moto G (lollipop).
Compile and run from the b4a ide, the app is started as soon as the ide installs it.
The service starts, disables the Main activity and displays a toast message.

I hit the home key and then the app tray - i very briefly see the 'Hide Launcher Icon' app in the app tray.
Then it disappears - the Moto G launcher has refreshed itself and no longer displays the app.

I reboot the Moto G and see the toast message after reboot.

I go to Settings > Apps and 'force stop' the app and reboot again.

No sign of the toast message this time after a reboot.
The Main activity is now disabled and the app is in a 'stopped state'.

I return to Settings > Apps and uninstall the app.

So it's a solution for hiding the app from the launcher.
What will you do if your app user kills or force stops your app?

Martin.
 

Attachments

  • HideLauncherIcon.zip
    8.2 KB · Views: 655
Upvote 0
Top