Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Apk after app installation

I am working on an app in which I have to restrict the user to share the apk personally. One can download it but should not be allowed to share the App (apk) personally via bluetooth etc.

I searched and read alot about the same issue but didn't find a complete answer. I have tried the below.

  1. How to get the file *.apk location in Android device

  2. Download, Installing and Delete .apk file on android device programmatically from a website other than marketplace

What I have understood from above is that the easy way to do this is to delete the apk file from the User's device after the app is installed. (I also know that user may generate this apk again via root access but that is fine as at-least I will be able to restrict not all but many).

Now what I have tried, I am registering a Broadcast receiver and in my onReceive() method I have the below,

PackageManager pm = getPackageManager();

for (ApplicationInfo app : pm.getInstalledApplications(0)) {
 if (myPackage.equalsIgnoreCase(app.packageName)) {
    apkPath = app.sourceDir;
    break;
 }
}
Log.d("Package", myPackage + " - APK - " + apkPath);
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
    File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard, apkPath);
    file.delete();
}

But this does nothing as I am not aware of the IntentFilter I should use to register this.

Can any one guide me on what is the next step? and in case I am completely on a wrong land then help me achieve the above?

Any help will be appreciated. :)

like image 216
Atul O Holic Avatar asked Mar 19 '23 17:03

Atul O Holic


1 Answers

On later versions of Android, some (all?) broadcasts aren't sent to an app until it has been manually opened at least once. This is a security feature that can't be circumvented.

like image 181
scottt Avatar answered Mar 31 '23 21:03

scottt