#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