I'm developing an app which stores info about Calls and Messages. I don't want the user to uninstall the app without entering a password. I want to prevent the user to do that. I've looked into these links too, but I couldn't get a clue: Ask for password before uninstalling application
here's what I've wrote:
Android Manifest
<receiver android:name=".DetectRemoved" >
<intent-filter android:priority="999999">
<action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Java Code
public class DetectRemoved extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("activity_log.pargansystem.com.activity_log")){
Toast.makeText(context, "your message", Toast.LENGTH_SHORT).show();
// start your activity here and ask the user for the password
}
}
}
}
}