N
N
namee2019-12-06 11:21:48
Android
namee, 2019-12-06 11:21:48

How to clear the application cache?

Good day.
The essence of the problem is the following.
Application written in Unity, hosted by Google.
When updating from the store, an unpleasant situation occurs ..
If native plugins are updated inside, then the first time the application crashes with an error.
It is logical to assume that clearing the application cache and force quitting after the update will solve the problem.
With forced completion, everything is more or less clear and simple.
But with cleaning the cache - an ambush.
I tried to clean the folder with the project files, but it does not help.

File dir = context.getCacheDir();
deleteDir(dir);

This method solves the problem , but in parallel and erases all user data
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);

Who knows the solution to this problem?
The native method is not available to mere mortals.
/**
     * Attempts to delete the cache files associated with an application.
     * Since this may take a little while, the result will
     * be posted back to the given observer.  A deletion will fail if the calling context
     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
     * named package cannot be found, or if the named package is a "system package".
     *
     * @param packageName The name of the package to delete
     * @param observer An observer callback to get notified when the cache file deletion
     * is complete.
     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
     * will be called when that happens.  observer may be null to indicate that
     * no callback is desired.
     *
     * @hide
     */
    @UnsupportedAppUsage
    public abstract void deleteApplicationCacheFiles(@NonNull String packageName,
            @Nullable IPackageDataObserver observer);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question