Pages

Tuesday, December 18, 2018

How to Hide App in Android studio?




In activity_main.xml

Add a Button to click.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
   xmlns:tools="http://schemas.android.com/tools" 
   xmlns:app="http://schemas.android.com/apk/res-auto" 
   android:layout_width="match_parent"  
  android:layout_height="match_parent"  
  tools:context="com.spidytechnology.hideappicon.MainActivity">

    <Button     
       android:layout_width="wrap_content"  
       android:layout_height="wrap_content" 
       android:text="CLick to Hide App"   
       android:id="@+id/button"
        android:layout_centerInParent="true"        />
</RelativeLayout>


# In MainActivity.Java

Add this following Codes

public class MainActivity extends AppCompatActivity {
    
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                PackageManager packageManager = getPackageManager();
                ComponentName componentName = new ComponentName(MainActivity.this, MainActivity.class);
                packageManager.setComponentEnabledSetting(componentName,
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

                Toast.makeText(MainActivity.this, "App Hide Successfully", Toast.LENGTH_SHORT).show();
            }
        });
           }
     }

No comments:

Post a Comment