Android Api (Okhttps) 未在 android 9(pie) 及更高版本中调用

编程入门 行业动态 更新时间:2024-10-21 03:39:08
本文介绍了Android Api (Okhttps) 未在 android 9(pie) 及更高版本中调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在以与其他手机版本相同的方式调用 android API,并且在 Oreo 版本(即 8)之前它工作正常.但是在 android 9(即 pie 版本及更高版本)中没有调用该 API.如果馅饼有一些变化,请告诉我.提前致谢.

I am calling the android API in the same way as for other versions of phone and its working fine till Oreo version i.e. 8. But the API is not getting called in android 9 i.e. pie version and above. If there are some changes in pie, do let me know. Thanks in advance.

 private void getLoginAPI(String username, String password, String compnaycoce) {

    if (NetworkStatus.isNetworkConnected(this)) {
        LoginReqBean bean = new LoginReqBean();
        bean.UserId = username;
        bean.Password = password;
        bean.Company = compnaycoce;
        NetworkService serviceCall = new NetworkService(Constants.loginPost(), Constants.TAG_POST, this);
        serviceCall.call(bean);
    } else
        Toast.makeText(this, "Please check Internet connection", Toast.LENGTH_SHORT).show();
}

@Override
public void onNetworkCallInitiated(String service) {
    progressDialog = ProgressDialog.show(LoginActivity.this, "Info", "Validating Credentials, Please wait...");
    progressDialog.show();

}

 @Override
  public void onNetworkCallCompleted(String service, String response) {
    Log.e("LOGIN JSON ", "login " + response);

    if (progressDialog != null && progressDialog.isShowing())
        progressDialog.dismiss();

    LoginParentBean parentBean = LoginParentBean.fromJson(response);

    if (parentBean != null && parentBean.status) {
        LoginBean loginBean = parentBean.result;
        Toast.makeText(getApplicationContext(), "You Are logged in Successfully!", Toast.LENGTH_LONG).show();
        AppPreferences.INSTANCE.setUserID(loginBean.user_id);
        AppPreferences.INSTANCE.setUserRole(loginBean.userRole);
        AppPreferences.INSTANCE.setUserLocation(loginBean.location);
        AppPreferences.INSTANCE.setUserLocationID(loginBean.locationId);
        AppPreferences.INSTANCE.setIsPostGres(loginBean.isPostgres);
        AppPreferences.INSTANCE.setUserName(loginBean.username);
        AppPreferences.INSTANCE.setAccessToken(loginBean.tokenValue);
        AppPreferences.INSTANCE.setLogin(true);

        Intent intent = new Intent(getApplicationContext(), DashBoardActivity.class);
        startActivity(intent);
        finish();
    } else
        Toast.makeText(getApplicationContext(), "Please check your username and password again!", Toast.LENGTH_LONG).show();


}

@Override
public void onNetworkCallError(String service, String errorMessage) {
    if (progressDialog != null && progressDialog.isShowing())
        progressDialog.dismiss();

    MessageDialog msg = new MessageDialog(LoginActivity.this);
    msg.setButtonText("Ok");
    msg.show(getResources().getString(R.string.error_somethingwent), getResources().getString(R.string.app_name));
}
}

推荐答案

Android 6.0android manifest 的 application 元素下引入了 useCleartextTraffic 属性强>.Android P 中的默认值为false".将此设置为 true 表示应用打算使用清晰的网络流量.

Android 6.0 introduced the useCleartextTraffic attribute under the application element in the android manifest. The default value in Android P is "false". Setting this to true indicates that the app intends to use clear network traffic.

<application
    android:usesCleartextTraffic="true"

</application>

然而,这似乎可以解决问题,但却对数据完整性构成威胁.Android 7.0 通过网络安全配置文件提供了更好的解决方案

However, this may appear to fix the problem but it opens a threat to data integrity. A better solution is offered in Android 7.0 through network security configuration file

这篇关于Android Api (Okhttps) 未在 android 9(pie) 及更高版本中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 04:50:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/930506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更高   版本   Api   Android   Okhttps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!