0

I am developing an application in which the requirement is hide app icon after installation.Means app icon will never display any where in home screen. I will launch app by using shortcode. Below code for hiding app ico.

 ComponentName componentToDisable = new ComponentName(context, Splash.class);
    context.getPackageManager().setComponentEnabledSetting(componentToDisable,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);

But my question is

how can i call above line of code just after installation of my application.

How I will identify that my application is just installed.

I have added below broadcast in menifest file

  <receiver android:name=".utilities.InstallApplicationReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
        </intent-filter>
    </receiver>

below is my bradcast class

public class InstallApplicationReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equalsIgnoreCase("android.intent.action.PACKAGE_ADDED")) {
        ComponentName componentToDisable = new ComponentName(context, Splash.class);
        context.getPackageManager().setComponentEnabledSetting(componentToDisable, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
}

}

but still its not hiding app icon :(

Android dev
  • 273
  • 2
  • 5
  • 23
  • There is a Broadcast Action called `ACTION_PACKAGE_ADDED` which is available to applications [_except the newly added application_](https://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED). What this means is quite simply this: The user will have to run your application _at least_ once for your code to remove the app icon. Either that, or do what the two answers suggest. – Siddharth Lele Jul 30 '16 at 09:06
  • hide icon from home screen or from app drawer? – dipali Jul 30 '16 at 10:13
  • Application icon will never display to user.After first installation of application in mobile – Android dev Jul 30 '16 at 10:21

3 Answers3

0

Remove this intent filter from manifest file for Splash activity and you will not see your app in home screen.

<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
Vivart
  • 14,900
  • 6
  • 36
  • 74
  • By using above code I can able to hide launcher icon,but application is not opening by using secret code.Means earliar i am able to open application by dailing secretcode .EX *#*#1223#*#* – Android dev Jul 30 '16 at 09:43
0

Or you can try removing this part from AndroidManifest.xml of your app.

 <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
Myo Ko
  • 108
  • 8
  • By using above code I can able to hide launcher icon,but application is not opening by using secret code.Means earliar i am able to open application by dailing secretcode .EX #*#1223#*# – Android dev Jul 30 '16 at 09:44
-1

//Hide App Icon

PackageManager p = context.getPackageManager();
                        ComponentName componentName = new ComponentName(this,SplashActivity.class);
                        p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Receiver for Outgoing call so you can open app from dialer pad:

public class CodeReceiver  extends BroadcastReceiver

{

    SharedPreferences preferences;

    @Override
    public void onReceive(Context context, final Intent intent) {

        preferences=context.getSharedPreferences(Constant.PREF_NAME, context.MODE_PRIVATE);



            if (intent.getAction().equals(android.content.Intent.ACTION_NEW_OUTGOING_CALL)){
                String phoneNumber=intent.getExtras().getString(android.content.Intent.EXTRA_PHONE_NUMBER);

                if(phoneNumber.equals((Constant.PINCODE_).toString())) {

                    setResultData(null);

                   PackageManager p = context.getPackageManager();
                    ComponentName componentName = new ComponentName("apppackage","apppackage.firstscreen");
                    p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

                    Intent i = new Intent(context, SplashActivity.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(i);

                }
            }


    }
}

Manifest:

  <receiver
            android:name=".classes.CodeReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </receiver>
ViramP
  • 1,659
  • 11
  • 11
  • You can use below: To Hide app icon from launcher programatically you can do this PackageManager packageManager = context.getPackageManager(); ComponentName componentName = new ComponentName(context, LauncherActivity.class); packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); To launch app by pressing number first add folowing permission in mainfest file – ViramP Jul 30 '16 at 09:52
  • This is a bad suggestion. The application will have to seek a permission which is completely unwanted / unwarranted for hiding the app icon! An application should never ask for permissions it is never going to use. That is just bad development! Besides, the OP is only interested in hiding the app icon in this question. Not "_how to open an app after hiding the app icon_". – Siddharth Lele Jul 30 '16 at 10:59