Uninstall Apk after installing the application

I am working on an application in which I have to restrict access to a personal apk user. It can be downloaded, but you should not allow application sharing (apk) via Bluetooth, etc.

I searched and read a lot about the same problem, but did not find a complete answer. I tried the following.

What I understood above is that an easy way to do this is to remove the apk file from the user device after installing the application. (I also know that the user can generate this apk again via root access, but this is normal, at least I can limit not everything, but many).

Now that I tried, I register the Broadcast receiver and in my method onReceive()I have 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, because I do not know the IntentFilter, which I have to use to register this.

Can someone direct me to the next step? and if I'm completely on the wrong land, then help me reach higher?

Any help would be appreciated. :)

+4
source share
6 answers

In later versions of Android, some (all?) Broadcasts are not sent to the application until it is manually opened at least once. This is a safety feature that cannot be bypassed.

+2
source

, . Android Api : "ACTION_PACKAGE_ADDED" . :

- apk.

+2

.

:

1) , - .

2) broadcastreciver , onRecive()       ,

   private boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

  , ,

3), isPackageInstalled ( "com.download.app", )   apk SD-

, .

+1

, . , apk. , apk . , .

public static String link = Environment.getExternalStorageDirectory()
        .getPath() + "/Android/data/YourAppPackageName/";

//check if its running for the first time
    File f = new File(link);
    if (f.exists()) {

       File f1 = new File("/data/app/YourAppPackageName.apk")
       if(f1.exists()){f1.delete();}
    }
    else {
    f.mkdirs();
    }
0

HockeyApp Android, , . , , , .

0

Source: https://habr.com/ru/post/1539250/


All Articles