1

i am making a security related android app. in which i want to restrict user to uninstall the android app by password, at the time of app installation i want to get input password from user and during uninstallation user must enter the same password to uninstall it. without entering that password he should not uninstall the app.

i searched over internet and asked many android developers but nobody can sort it out. This type of security exist in quick heal app (quick heal antivirus for mobile), so it is possible. some says it cant be possible with normal android SDK, it requires administrative API. some says it cant possible.

please suggest me if anyone have solution

i tried out package watcher through broadcast receiver and reached almost near by to my goal. but at the time of uninstallation two package installer generates, one is the default (implicit) and one is created by me (explicit). when user select "my package installer" then he prompt for password and everything goes as desired but when user selects default package installer then the app got uninstall without asking for password.

anyone here to solve this issue???????

Avinash Sharma
  • 60
  • 1
  • 13

1 Answers1

0

You can detect uninstall pop up of any app(including your own app) using Accessibility Service.

public class MyService extends AccessibilityService {


@Override
public void onCreate() {
    super.onCreate();

}

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {

    if(event.getText().equalsIgnoreCase("check for content in popup which is in screenshot"){

            /**Here display a popup to enter password*/
        }
    }

}

@Override
public void onInterrupt() {

}


@Override
protected void onServiceConnected() {
    super.onServiceConnected();

    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.flags = AccessibilityServiceInfo.DEFAULT;
    info.packageNames = new String[]{"com.android.packageinstaller"};
    info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    setServiceInfo(info);
}

}

here in onServiceConnected, com.android.packageinstaller represents the install/uninstall app package name(this is system app and it doesn't have any UI so it will not shown to users.).

enter image description here