Closed dineshchavhan closed 3 years ago
Hi, the NetworkOnMainThreadException occurs when an application attempts to perform a networking operation on its main thread, so for using GroupDocs API calls, an async task should be used, for example: ` @SuppressLint("StaticFieldLeak") private class GetDataTask extends AsyncTask<Void, Void, Boolean> { @Override protected Boolean doInBackground(Void... params) {
String appSid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
String appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Configuration configuration = new Configuration(appSid, appKey);
InfoApi infoApi = new InfoApi(configuration);
try {
FormatsResult response = infoApi.getSupportedFileFormats();
for (Format format : response.getFormats()) {
System.out.println(format.getFileFormat());
}
return true;
} catch (ApiException e) {
System.err.println("Failed to get supported file formats");
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(final Boolean success) {
mTask = null;
}
@Override
protected void onCancelled() {
mTask = null;
}
}
`
code is
error occur Caused by: android.os.NetworkOnMainThreadException