Disable unistall app in android?

I want such an application to be installed on an Android phone. no authority can remove it from the phone, or when someone tries to remove it, a pop-up show, or any warning. Is there any way?

+3
source share
4 answers

You will need to enable deviceAdmin to disable Force Stopand functions Uninstall. It is processed Device Admin APIthat handles enterprise / application policy management.

+7
source

Disabling is clearly not possible. However, you can use a workaround for this. Create a service in your application that runs continuously in the background:

//MasterService.java
public class MasterService extends Service{

    private ThreadPoolExecutor executor;
    private Runnable runnable = new Runnable(){
        @Override
        public void run(){}
    };

    public MasterService(){
        executor = new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, 
                       new LinkedBlockingQueue<Runnable>());
    }

     @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        executor.execute(runnable);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        executor.shutdown();
    }

};

startService(new Intent(this, MasterService.class)); .

Android ( ), , . Runnable , . , , :

//MasterService.java (inside runnable)
@Override
public void run(){
    while(true) {
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();

        for (int i = 0; i < procInfos.size(); i++) {
            //check if package installer runs in foreground
            if (procInfos.get(i).processName.equals("com.android.packageinstaller") && procInfos.get(i).importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {

                //start activity
                startActivity(new Intent(MasterService.this, OverlayActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY));
            }
        }
    }
}

"", :

//OverlayActivity.java
public class OverlayActivity extends Activity{

    private ImageView view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = new ImageView(this);
        setContentView(view);
    }


    @Override
    public void onBackPressed() {

    }
};

"" , , "", , OverlayActivity . , ​​ . :

  • onDestroy , .
  • , com.android.settings.

, , , , .

+2

"" , ( ), "" . , . " ".

+1

, , , - .

  • .. , , , .
  • - , ,

.. . , .. , .

You may be able to configure the system, and this may give you access to the idea of ​​an administrator. Not sure if this will work.

0
source

All Articles