编程知识 cdmana.com

[Android primary] how to make app unable to run on the specified system version

As there are more and more three parties on the market APP Appearance , Some mobile phone manufacturers are also beginning to pay attention to these APP There are installation restrictions or operation restrictions , Or three parties APP Its version is too low , Cannot be supported by a specific system version .

Today I'm going to simulate a “ because APP Its version is too low 、 Causes it to fail to run on the current version of the system ” Functional effect of .

The implementation idea is as follows :

  1. To get APP The target running version of , Also know the compiled version of the system

  2. By comparing versions , In entering the APP when , Make decisions for users “ Running... Is not supported ” A hint of

  3. After the user confirms the prompt , Exit the program directly APP

The key point is targetSdkVersion Use , Source code is as follows :

1、 Lord Activity

public class TargetSdkVersionDemo extends Activity { @Override protected void onCreate(Bundle onSavedInstance) {  super.onCreate(onSavedInstance);  setContentView(R.layout.target_sdk_version_demo);  int appTargetSdkVersion = getApplicationInfo().targetSdkVersion;  Log.i("TargetSdkVersionDemo", "targetsdkversion " + appTargetSdkVersion);    //  Let's assume this APP The target running version of is no higher than  API Level 26  if (appTargetSdkVersion <= Build.VERSION_CODES.O) {   showNotSupportDialog(appTargetSdkVersion);  } } private void showNotSupportDialog(int version) {  new AlertDialog.Builder(this)    .setMessage(" The APP The target run version of is  " + version + ", Lower than the current version of the phone , Running... Is not supported !")    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {     @Override     public void onClick(DialogInterface dialog, int which) {      //  Exit procedure       finish();     }    })    .create()    .show(); }}

版权声明
本文为[Program ape Owen]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/02/20210201000559578A.html

Scroll to Top