0

When uploading an image from gallery to Rest API works fine on old Android devices. The image is uploaded perfectly to server. But when I upload it using new Android Pie device, image is not uploaded.

    @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);

        }
    }
Jonathan JOhx
  • 5,784
  • 2
  • 17
  • 33
Taps
  • 27
  • 6

1 Answers1

0

For Android PIE you need to declare a network-permission.

  1. Go to your res folder, and search for a xml folder (if you don't have it then create it).

  2. Create a file i usually named it: network_security.xml but you can call it however you like.

  3. Inside the file .xml add your domain.

<?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>
  1. Open your AndroidManifest and add this.

<application
                android:icon="@mipmap/ic_launcher"
                android:label="@string/app_name"
                android:networkSecurityConfig="@xml/network_security_config"

This should help with your problem.

Luis Cardoza Bird
  • 1,265
  • 4
  • 24
  • 43
  • I have add this things before that has not a issue but when i am upload image from gallery it sets in mobile but when it sends to server then image is not uploaded to server. I have used Multiparts – Taps Sep 25 '19 at 09:19