我的应用程序在除Pie版本之外的所有android版本中都运行良好。 在Pie中,它显示没有互联网连接,而我通过Wifi和移动数据进行了检查。此问题与Pie版本有关。
i尝试以下解决方案:
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
但是两个都没有。
这是我的“登录”按钮代码,其中包含在OnFailure中
private void onLoginUser(String email, String password) {
Call<LoginModel> call = ApiClient.getClientInstance().getClientService().userlogin(email, password);
call.enqueue(new Callback<LoginModel>() {
@Override
public void onResponse(Call<LoginModel> call, Response<LoginModel> response) {
mProgressBar.setVisibility(View.GONE);
LoginModel jsonLoginResult = response.body();
if (response.code()== 200) {
Log.e("Response", response.code() + "");
}
if (response.code() == 400 ) {
Utility.getInstance(LoginActivity.this).showSnackBarLong(response.message(), mLoginActivity);
return;
}
if (response.code() == 404 ) {
Utility.getInstance(LoginActivity.this).showSnackBarLong(response.message(), mLoginActivity);
return;
}
if (response.code() == 500 ) {
Utility.getInstance(LoginActivity.this).showSnackBarLong(response.message(), mLoginActivity);
return;
}
if (jsonLoginResult == null ) {
Utility.getInstance(LoginActivity.this).showSnackBarLong("Data not found", mLoginActivity);
return;
}
if (jsonLoginResult != null && response != null && response.isSuccessful() && response.body() != null) {
String jError = "" ;
String jMessage = "" ;
String jUserStatus = "" ;
try {
jError = String.valueOf(jsonLoginResult.getError());
jMessage = String.valueOf(jsonLoginResult.getMessage());
jUserStatus = String.valueOf(jsonLoginResult.getStatus());
}catch (NullPointerException e){
Log.d("Result", e+"");
}
TelephonyManager mTelephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
@SuppressLint("MissingPermission")
String phone_imei= mTelephonyManager.getDeviceId();
myPreference.saveString(Constants.IMEI_NUMBER , phone_imei);
if(jUserStatus.equals(0) || jUserStatus.equalsIgnoreCase("0")){
myPreference.saveString(Constants.USER_STATUS , "Disapproved");
}
if(jUserStatus.equals(1)|| jUserStatus.equalsIgnoreCase("1")){
myPreference.saveString(Constants.USER_STATUS , "Approved");
}
if(jUserStatus.equals(3)|| jUserStatus.equalsIgnoreCase("3")){
myPreference.saveString(Constants.USER_STATUS , "Under Process");
}
if(jError.equalsIgnoreCase("false")){
String jUserId = String.valueOf(jsonLoginResult.getId());
String jUserApikey = String.valueOf(jsonLoginResult.getApikey());
String jUserName = String.valueOf(jsonLoginResult.getName());
String jUserEmail = String.valueOf(jsonLoginResult.getEmail().trim());
String jUserPhone = String.valueOf(jsonLoginResult.getPhone_no().trim());
String jUserRegisterDate = String.valueOf(jsonLoginResult.getCreated_at());
String jUserLogin_date = String.valueOf(jsonLoginResult.getLogin_date());
String jUserPancardImage = String.valueOf(jsonLoginResult.getPan_card_image());
String jUserChequeImage = String.valueOf(jsonLoginResult.getCheque_number_image());
String jUserAddressImage = String.valueOf(jsonLoginResult.getAddressProofImage());
String jAddress = String.valueOf(jsonLoginResult.getAddress());
String jCompanyName = String.valueOf(jsonLoginResult.getCompanyName());
String jCountryId = String.valueOf(jsonLoginResult.getCountryId());
String jStateId = String.valueOf(jsonLoginResult.getStateId());
String jCityId = String.valueOf(jsonLoginResult.getCityId());
String jStateName = String.valueOf(jsonLoginResult.getStateName());
String jCityName = String.valueOf(jsonLoginResult.getCityName());
String jRelationShipManager = String.valueOf(jsonLoginResult.getRelationshipManagerId());
Utility.getInstance(LoginActivity.this).showSnackBarLong(jMessage, mLoginActivity);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try {
mUNameLogin.setText("");
mPasswordLogin.setText("");
Intent i = new Intent(LoginActivity.this, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
LoginActivity.this.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}, 2000);
}
if(jError.equalsIgnoreCase("null")){
Utility.getInstance(LoginActivity.this).showSnackBarLong(jMessage, mLoginActivity);
return;
}
if(jError.equalsIgnoreCase("true")){
popupMessageDialog(jMessage);
//return;
}
}
else {
assert response != null;
Utility.getInstance(LoginActivity.this).showSnackBarLong(" "+response.message(), mLoginActivity);
return;
}
}
@Override
public void onFailure(Call<LoginModel> call, Throwable t) {
mProgressBar.setVisibility(View.GONE);
if (LoginActivity.this != null) {
Utility.getInstance(LoginActivity.this).showSnackBarLong("No Internet Connection", mLoginActivity);
return;
}
}
});
答案 0 :(得分:0)
尝试下面的两件事,从您的应用程序标记中删除networkSecurityConfig
,然后在您的应用程序标记中添加以下代码,然后尝试
<application
android:name=".MyApplication"
android:allowBackup="true"
android:enabled="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/generalnotitle"
android:usesCleartextTraffic="true">
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />