Download failed with error 400 when using Android Pie
I've been using DownloadManager in a production app without problems but now it fails in Android Pie (API 28). Please note that the download is marked as failed and returns error 400.
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(reference);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(statusIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
int fileUriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String savedFileUri = cursor.getString(fileUriIndex);
ParcelFileDescriptor pfd = null;
try {
pfd = context.getContentResolver().openFileDescriptor(Uri.parse(savedFileUri), "r");
PamplonaParkingXMLParser pamplonaParkingXMLParser = new PamplonaParkingXMLParser();
ParkingList parkingList = pamplonaParkingXMLParser.parse(pfd);
ObservableObject.getInstance().updateValue(parkingList);
if (pfd != null) {
pfd.close();
}
} catch (XmlPullParserException e) {
Log.e(TAG, e.getDetail().getLocalizedMessage());
} catch (IOException | NullPointerException e) {
Log.e(TAG, e.getLocalizedMessage());
}
} else if(status == DownloadManager.STATUS_FAILED){
Log.e(TAG, "Download failed");
int reasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(reasonIndex);
Log.e(TAG, reason +"");
}
}
android android-download-manager android-9.0-pie
add a comment |
I've been using DownloadManager in a production app without problems but now it fails in Android Pie (API 28). Please note that the download is marked as failed and returns error 400.
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(reference);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(statusIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
int fileUriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String savedFileUri = cursor.getString(fileUriIndex);
ParcelFileDescriptor pfd = null;
try {
pfd = context.getContentResolver().openFileDescriptor(Uri.parse(savedFileUri), "r");
PamplonaParkingXMLParser pamplonaParkingXMLParser = new PamplonaParkingXMLParser();
ParkingList parkingList = pamplonaParkingXMLParser.parse(pfd);
ObservableObject.getInstance().updateValue(parkingList);
if (pfd != null) {
pfd.close();
}
} catch (XmlPullParserException e) {
Log.e(TAG, e.getDetail().getLocalizedMessage());
} catch (IOException | NullPointerException e) {
Log.e(TAG, e.getLocalizedMessage());
}
} else if(status == DownloadManager.STATUS_FAILED){
Log.e(TAG, "Download failed");
int reasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(reasonIndex);
Log.e(TAG, reason +"");
}
}
android android-download-manager android-9.0-pie
add a comment |
I've been using DownloadManager in a production app without problems but now it fails in Android Pie (API 28). Please note that the download is marked as failed and returns error 400.
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(reference);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(statusIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
int fileUriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String savedFileUri = cursor.getString(fileUriIndex);
ParcelFileDescriptor pfd = null;
try {
pfd = context.getContentResolver().openFileDescriptor(Uri.parse(savedFileUri), "r");
PamplonaParkingXMLParser pamplonaParkingXMLParser = new PamplonaParkingXMLParser();
ParkingList parkingList = pamplonaParkingXMLParser.parse(pfd);
ObservableObject.getInstance().updateValue(parkingList);
if (pfd != null) {
pfd.close();
}
} catch (XmlPullParserException e) {
Log.e(TAG, e.getDetail().getLocalizedMessage());
} catch (IOException | NullPointerException e) {
Log.e(TAG, e.getLocalizedMessage());
}
} else if(status == DownloadManager.STATUS_FAILED){
Log.e(TAG, "Download failed");
int reasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(reasonIndex);
Log.e(TAG, reason +"");
}
}
android android-download-manager android-9.0-pie
I've been using DownloadManager in a production app without problems but now it fails in Android Pie (API 28). Please note that the download is marked as failed and returns error 400.
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(reference);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(query);
cursor.moveToFirst();
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(statusIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
int fileUriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String savedFileUri = cursor.getString(fileUriIndex);
ParcelFileDescriptor pfd = null;
try {
pfd = context.getContentResolver().openFileDescriptor(Uri.parse(savedFileUri), "r");
PamplonaParkingXMLParser pamplonaParkingXMLParser = new PamplonaParkingXMLParser();
ParkingList parkingList = pamplonaParkingXMLParser.parse(pfd);
ObservableObject.getInstance().updateValue(parkingList);
if (pfd != null) {
pfd.close();
}
} catch (XmlPullParserException e) {
Log.e(TAG, e.getDetail().getLocalizedMessage());
} catch (IOException | NullPointerException e) {
Log.e(TAG, e.getLocalizedMessage());
}
} else if(status == DownloadManager.STATUS_FAILED){
Log.e(TAG, "Download failed");
int reasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(reasonIndex);
Log.e(TAG, reason +"");
}
}
android android-download-manager android-9.0-pie
android android-download-manager android-9.0-pie
asked Dec 31 '18 at 9:16
Xabi VazquezXabi Vazquez
176313
176313
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try these solutions
Solution 1)
Add this line in application tag in manifest
file
android:usesCleartextTraffic="true"
like below
<application
android:name=".ApplicationClass"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Add this tag in application tag in manifest
file
Solution 2)
Add android:networkSecurityConfig="@xml/network_security_config"
in application tag
<application
android:name=".ApplicationClass"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
where network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Create xml
under res directory and then network_security_config.xml
in xml
folder
For more info refer my answer
Files are not downloading on Android Pie 9.0 (Xiaomi mi A2) Using Download Manger
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985649%2fdownload-failed-with-error-400-when-using-android-pie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try these solutions
Solution 1)
Add this line in application tag in manifest
file
android:usesCleartextTraffic="true"
like below
<application
android:name=".ApplicationClass"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Add this tag in application tag in manifest
file
Solution 2)
Add android:networkSecurityConfig="@xml/network_security_config"
in application tag
<application
android:name=".ApplicationClass"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
where network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Create xml
under res directory and then network_security_config.xml
in xml
folder
For more info refer my answer
Files are not downloading on Android Pie 9.0 (Xiaomi mi A2) Using Download Manger
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
add a comment |
Try these solutions
Solution 1)
Add this line in application tag in manifest
file
android:usesCleartextTraffic="true"
like below
<application
android:name=".ApplicationClass"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Add this tag in application tag in manifest
file
Solution 2)
Add android:networkSecurityConfig="@xml/network_security_config"
in application tag
<application
android:name=".ApplicationClass"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
where network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Create xml
under res directory and then network_security_config.xml
in xml
folder
For more info refer my answer
Files are not downloading on Android Pie 9.0 (Xiaomi mi A2) Using Download Manger
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
add a comment |
Try these solutions
Solution 1)
Add this line in application tag in manifest
file
android:usesCleartextTraffic="true"
like below
<application
android:name=".ApplicationClass"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Add this tag in application tag in manifest
file
Solution 2)
Add android:networkSecurityConfig="@xml/network_security_config"
in application tag
<application
android:name=".ApplicationClass"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
where network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Create xml
under res directory and then network_security_config.xml
in xml
folder
For more info refer my answer
Files are not downloading on Android Pie 9.0 (Xiaomi mi A2) Using Download Manger
Try these solutions
Solution 1)
Add this line in application tag in manifest
file
android:usesCleartextTraffic="true"
like below
<application
android:name=".ApplicationClass"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Add this tag in application tag in manifest
file
Solution 2)
Add android:networkSecurityConfig="@xml/network_security_config"
in application tag
<application
android:name=".ApplicationClass"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
where network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
Create xml
under res directory and then network_security_config.xml
in xml
folder
For more info refer my answer
Files are not downloading on Android Pie 9.0 (Xiaomi mi A2) Using Download Manger
answered Dec 31 '18 at 9:21
Quick learnerQuick learner
2,5011924
2,5011924
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
add a comment |
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
1
1
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
Thank you, I was using <domain-config cleartextTrafficPermitted="true"> and so on trying to explicitly allow only clear text traffic to a domain, but didn't work. Your solution finally solved the issue.
– Xabi Vazquez
Dec 31 '18 at 19:01
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
i am glag it worked , please accept my answer to others so others can use it
– Quick learner
Jan 2 at 5:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985649%2fdownload-failed-with-error-400-when-using-android-pie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown