Android приложение работает на старой версии, а новой - нет

У многих увидел проблемы того, что не поддерживается старая версия android, у меня ситуация противоположная: на устройствах с android 9 и 10, пробовал на xiaomi mi 9t, xiaomi mi a3 и honor 9, программа не работает (запускается, но свои действия не выполняет), а на старом устройстве с 5 android (api 22) все работает как и должно (meizu m3s) Вот файл активности

public class MainActivity extends AppCompatActivity
{

    private Button on_button;
    private Button off_button;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        on_button = (Button) findViewById(R.id.on_button);
        off_button = (Button) findViewById(R.id.off_button);
        Toast toast_fail = Toast.makeText(MainActivity.this, "Отправка не выполнена", Toast.LENGTH_LONG);
        Toast toast_ok = Toast.makeText(MainActivity.this, "Отправка выполнена", Toast.LENGTH_LONG);


        on_button.setOnClickListener(new View.OnClickListener()  // обработка нажатия кнопки on
        {
            @Override
            public void onClick(View v) {
                String url = "http://192.168.0.110/1/0";
                Request request = new Request.Builder()
                        .url(url)
                        .build();

                new OkHttpClient().newCall(request)
                        .enqueue(new Callback() {
                            @Override
                            public void onFailure(final Call call, IOException e) {
                                e.printStackTrace();
                                toast_fail.show();
                            }

                            @Override
                            public void onResponse(Call call, final Response response) throws IOException {
                                String res = response.body().string();
                                toast_ok.show();
                            }
                        });
            }
        });

        off_button.setOnClickListener(new View.OnClickListener()  // обработка нажатия кнопки off
        {
            @Override
            public void onClick(View v)
            {
                String url = "http://192.168.0.110/1/1";
                Request request = new Request.Builder()
                        .url(url)
                        .build();

                new OkHttpClient().newCall(request)
                        .enqueue(new Callback() {
                            @Override
                            public void onFailure(final Call call, IOException e) {
                                e.printStackTrace();
                                toast_fail.show();
                            }

                            @Override
                            public void onResponse(Call call, final Response response) throws IOException {
                                String res = response.body().string();
                                toast_ok.show();
                            }
                        });
            }
        });
    }
}

И build.gradle

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.deb.new_home"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

Помогите, пожалуйста, разобраться с проблемой


Ответы (0 шт):