在不同的API级别下运行Android Studio的Volley。

huangapple go评论54阅读模式
英文:

Running Android Studio Volley in different API levels

问题

我制作的应用程序在不同的API级别上运行,但Volley库只能在API级别26上运行。

当我尝试在我的手机(Android 9)上登录应用程序时,我感到困惑,但稍后型号的手机可以正常工作。后来我发现,只能在Android 8手机(API级别26)上登录。我测试了多个具有不同API级别的虚拟设备,发现只有API级别26允许我登录,其他的都不起作用。我想知道如何使Volley库在API级别26及更高版本上工作。

编辑:这是我的一个大错误,但我现在已启用了错误日志并发现了以下问题。

(使用http://)
在不同的API级别下运行Android Studio的Volley。

(使用https://)
在不同的API级别下运行Android Studio的Volley。

plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.studentplanner"
        minSdk 26
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    buildFeatures {
        viewBinding true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    namespace 'com.example.studentplanner'
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'com.github.xabaras:RecyclerViewSwipeDecorator:1.3'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.code.gson:gson:2.9.1'

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
英文:

The app I made ran on different API levels but the volley library only works API level 26.

I was puzzled when I can't login in the app using my phone (android 9) but a later model works just fine. I found out that I can only login in Android 8 phones (API level 26). I tested multiple virtual devices with different API levels and API level 26 let's me login and the rest just doesn't work. I was wondering how can I make volley library work on API level 26 and higher.

Edit: It was a big mistake for me but I now enabled the log for errors and I found these.

(Using http://)
在不同的API级别下运行Android Studio的Volley。

(Using https://)
在不同的API级别下运行Android Studio的Volley。

plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.studentplanner"
        minSdk 26
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    buildFeatures {

        viewBinding true

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    namespace 'com.example.studentplanner'
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'com.github.xabaras:RecyclerViewSwipeDecorator:1.3'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.google.code.gson:gson:2.9.1'

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

答案1

得分: 1

在你的应用程序标签中添加以下行:

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>
英文:

Add this line in your application tag

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest ...&gt;
    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
    &lt;application
        ...
        android:usesCleartextTraffic=&quot;true&quot;
        ...&gt;
        ...
    &lt;/application&gt;
&lt;/manifest&gt;

huangapple
  • 本文由 发表于 2023年1月9日 09:04:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定