How to Hide Application Launcher Icon in Android

You can achieve this using Packagemanager setComponentEnabledSetting method.

Start by creating an Android application with one Activity and Broadcast Receiver; yes Broadcast Receiver will see how to use it to launch the hidden application.
In your main Activity add some UI to display to user and implement code for hidding application launcher icon.

Main Activity will look like

package com.demo.sampleapplication; import android.app.Activity; import android.content.ComponentName; import android.content.pm.PackageManager; import android.os.Bundle; public class EditTextActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edit_text_clickable_span); hideAppLauncher(); } private void hideAppLauncher(){ PackageManager p = getPackageManager(); ComponentName componentName = new ComponentName(this, com.demo.sampleapplication.MainActivity.class); p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } } So what we have done is we have setup UI as per client’s requirement and created a method hideAppLauncher which we are calling from Activity’s onCreate() method itself. So what will happen, moment employee closes the application, they won’t be able to see the application launcher icon nor application will be killed which we defined using PackageManager. DONT_KILL_APP flag of packagemanager setComponentEnabledSetting method.

Now if we wish to launch this application using we do not have any launcher icon. So to open we will implement a Broadcast Receiver for handling outgoing calls. So if user dials a particular number let’s say *00009999#, Broadcast Receiver will launcher unhide application launcher icon and then launch the application.

So in Broadcast Receiver add below code
import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.util.Log; public class AppBroadcastReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); if (phoneNumber.equals("*00009999#")){ unhideApp(context); Intent intent2 = new Intent(); intent2.setClass(context, EditTextActivity.class); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent2); } Log.d(AppBroadcastReceiver.class.getSimpleName(), phoneNumber); } private void unhideApp(Context context){ PackageManager p = context.getPackageManager(); ComponentName componentName = new ComponentName("com.demo.sampleapplication", "com.demo.sampleapplication.EditTextActivity"); p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } } After adding MainActivity and AppBroadcastReceiver details to AndroidManifest with required permission, Manifest will look like:-

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.sampleapplication" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".EditTextActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="com.demo.sampleapplication.AppBroadcastReceiver"> <intent-filter android:priority="9999"> <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> </intent-filter> </receiver> </application> </manifest> Remember unhiding application launcher icon is required else your will get ActivityNotFound exception.

Also another import thing to note here is while launching application from Broadcast Receiver don’t forget to setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), to Activity launcher Intent.

So that’s all, try running the application and check yourself.

Hope this article will help you in How to Hide Application Launcher Icon in Android. Android application Development experts are here to assist you, ask them your doubts about the subject.

 

Client Testimonials

  • Fabio Durso

    We found a reliable and efficient partner in NexSoftSys, ready to support our strategy of offshore software development. NexSoftSys has particularly impressed by the speed of response to any request for the development of software applications and for their maintenance.

  • Filipe

    We did hire full time Java developers from NexSoftSys, to help us to improve a time to market of a product. The software platform is based on Java & Extjs, and they are delivering the software on time and with success. We strongly recommend NexSoftSys as Reliable Development partner.

  • Steve

    Powerful solutions are given by NexSoftSys dedicated developers for my projects. They suggest solutions as per current market trend. Other than this, the team is always ready for any type of changes or update. That is the main reason that I would like to give my next project to them.

Copyright © 2016 - NexSoftSys All rights reserved