Ask for password before uninstalling application

前端 未结 4 1248
故里飘歌
故里飘歌 2020-11-29 09:47

First of all, I have researched a lot about my issue, but I could not find a proper solution so I am posting my query here. Hope to get a better solution to the issue:

4条回答
  •  [愿得一人]
    2020-11-29 10:15

    If this is a corporate requirement (if you want to block a regular user from uninstalling your app, no chance, thanks Google for protecting us from bad devs), you should create a device administrator application. This way, although the user still can delete the app, it's one extra step if you want to prevent accidental erasing.

    Before deleting your app, if it's enabled as device admin, the user must first disable the app as administrator, and the app receives this broadcast.

    In your XML, put

    
        
            
            
        
    
    
        
        
            
        
    
    

    In the receiver, you have at least two methods worth noticing:

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        …
    }
    
    @Override
    public void onDisabled(Context context, Intent intent) {
        …
    }
    

    This way you know the user is potentially going to erase your app.

    Complete guide for device administration is at https://developer.android.com/guide/topics/admin/device-admin.html

提交回复
热议问题