gpt4 book ai didi

java - Android Pie 中的图像从图库上传到服务器的问题

转载 作者:行者123 更新时间:2023-12-02 00:19:08 24 4
gpt4 key购买 nike

将图像从图库上传到 Rest API 在旧 Android 设备上运行良好。图像已完美上传到服务器。但是当我使用新的 Android Pie 设备上传它时,图像未上传。

    @Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
Uri SelectedImage = data.getData();
filePath = (String) getRealPathFromUri(getActivity(),data.getData());
photoFile = new File(filePath);
img_image.setImageURI(SelectedImage);

}
}

最佳答案

对于 Android PIE,您需要声明网络权限。

  1. 转到 res 文件夹,然后搜索 xml 文件夹(如果没有,则创建它)。

  2. 创建一个文件,我通常将其命名为:network_security.xml,但您可以随意命名它。

  3. 在 .xml 文件中添加您的域。

<?xml version="1.0" encoding="utf-8"?> <network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">IP ADDRESS IF LOCAL</domain>
<domain includeSubdomains="true">8.8.8.8</domain>
<domain includeSubdomains="true">myserverhosted.com</domain>
</domain-config> </network-security-config>

  • 打开您的 AndroidManifest 并添加此内容。
  • <application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"

    这应该有助于解决您的问题。

    关于java - Android Pie 中的图像从图库上传到服务器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58081586/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com