Cause analysis and solution Android9.0 Application pop "This application designed for older Android build, it may not work properly ..." questions

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/P876643136/article/details/94648077

       Individual old project still or use eclipse to develop, so sdk also use low, but this is not a problem. On Android P, the application will open the pop-up dialog box, content: "This application designed for older Android build, and therefore may not function properly, try to check for updates or contact the developer.".

                                                 

By following Android P source, analyze the reasons:

Application startup, startActivity, the flow to be performed realStartActivityLocked method, the code is ActivityStackSupervisor.java, realStartActivityLocked method, calls onStartActivity AppWarnings.java method, as follows:

final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, boolean andResume, boolean checkConfig) throws RemoteException {
    try {
        // ...
        mService.getAppWarningsLocked().onStartActivity(r);
        // ...
    } catch (RemoteException e) {
        // ...
    }
}

 onStartActivity ways:

/**
   * Called when an activity is being started.
   *
   * @param r record for the activity being started
   */
public void onStartActivity(ActivityRecord r) {
    showUnsupportedCompileSdkDialogIfNeeded(r);
    showUnsupportedDisplaySizeDialogIfNeeded(r);
    showDeprecatedTargetDialogIfNeeded(r);
}

The third function showDeprecatedTargetDialogIfNeeded which focuses on:

/**
   * Shows the "deprecated target sdk" warning, if necessary.
   *
   * @param r activity record for which the warning may be displayed
   */
public void showDeprecatedTargetDialogIfNeeded(ActivityRecord r) {
    if (r.appInfo.targetSdkVersion < Build.VERSION.MIN_SUPPORTED_TARGET_SDK_INT) {
        mUiHandler.showDeprecatedTargetDialog(r);
    }
}

Focus: Here appears a judgment method, it is their decision whether to pop, to determine the conditions Build.VERSION.MIN_SUPPORTED_TARGET_SDK_INT, as follows:

public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt(
                "ro.build.version.min_supported_target_sdk", 0);

The default value for this property, generally 17.

On Android P models, when applied targetSdk version is less than 17, it will pop when the application starts "This application designed for older Android build, so it might not work properly. Please try to check for updates or contact the developer."

View eclipse project, no targetSdk, but minSdkVersion

<uses-sdk android:minSdkVersion="8" />

The problem is still the same minSdkVersion to 16 in, changed 17 after the problem is solved.

Solve the core problem, continue to follow up realization showDeprecatedTargetDialog method, you will find the main dialog class is to call DeprecatedTargetSdkVersionDialog, to bring up this dialog, and displays the prompt.

There is a problem, since it is invoked onStartActivity method AppWarnings.java in each Activity starts, it will not be every time you open a new Activity, you are playing this dialog? If so, the user experience will be very bad.

Answer: No, here's a little trick, after the first pop-up dialog box, select the user if the "OK", AMS will give this app sets a Flag logo: FLAG_HIDE_DEPRECATED_SDK. Every time ready to pop, this identity will first determine whether the value is true, and if so, explained that it had been prompted users no longer need to pop. code show as below:

public DeprecatedTargetSdkVersionDialog(final AppWarnings manager, Context context, ApplicationInfo appInfo) {
    // ...
    final AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setPositiveButton(R.string.ok, (dialog, which) ->
                    manager.setPackageFlag(
                            mPackageName, AppWarnings.FLAG_HIDE_DEPRECATED_SDK, true))
                .setMessage(message)
                .setTitle(label);
    // ...
}

At last:

On Android P models, when applied targetSdk version is less than 17:00, it will pop when the application starts "This application designed for older Android build, so it might not work properly. Please try to check for updates or contact the developer." Ro.build.version.min_supported_target_sdk standard value by the set value, usually the default is 17. If the project is no eclipse targetSdk, it changed the minSdkVersion 17.

Guess you like

Origin blog.csdn.net/P876643136/article/details/94648077