Hi I'm trying to get all annotation that have URI to download the files in there, but I get fatal SIGSEV error sometimes, this is what I'm doing after open the document in onCreate.
Can someone help me and tell whats wrong?
class CheckURLInDocument extends AsyncTask<Void,Void,String>{
private ArrayList<FileDownload>urlDownload;
private Context context;
public CheckURLInDocument(Context context){
this.context=context;
}
@Override
protected String doInBackground(Void... params) {
try{
urlDownload=new ArrayList<FileDownload>();
Book book = Session.currentBook;
String path = Session.basePath;
int total = m_doc.GetPageCount();
attachments = new ArrayList<Attachment> ();
for (int i = 0; i < total; i++) {
Page page = m_doc.GetPage (i);
page.ObjsStart();
int annots = page.GetAnnotCount();
for (int j = 0; j < annots; j++) {
Page.Annotation annotation = page.GetAnnot(j);
if (annotation.GetURI() != null && annotation.GetURI() != "") {
if (annotation.GetURI().contains(".mp3")) {
File file = new File(path, annotation.GetURI());
if (!file.exists()) {
urlDownload.add(
new FileDownload(file,
URLEncoder.encode(book.getDesc(), "utf-8") + "/AUDIOS/" + annotation.GetURI(),
"Audio: " + annotation.GetURI()));
}
}
if (annotation.GetURI().contains(".mp4")) {
String[] names = annotation.GetURI().split("\\|");
Attachment a = new Attachment();
a.setPage(i);
a.setTitle(names[1]);
a.setName(names[0]);
attachments.add(a);
File file = new File(path, names[0]);
if (!file.exists()) {
urlDownload.add(new FileDownload(
file,
URLEncoder.encode(book.getDesclibro(), "utf-8") + "/VIDEOS/" + names[0],
"Video: " + names[1]));
}
}
}
annotation=null;
}
if(page!=null)
page.Close();
page=null;
}
}catch(Exception ex) {
ex.printStackTrace();
}
String res=downloadFiles();
return res;
}
@Override
protected void onPostExecute(String aVoid) {
super.onPostExecute(aVoid);
mAdapterAttachments=new AdapterAttachment(getApplicationContext(),attachments);
mListAttachments.setAdapter(mAdapterAttachments);
Toast.makeText(context,aVoid,Toast.LENGTH_SHORT);
}
public String downloadFiles(){
String url="http://.../../..";
String url2="http://.../../..";
String shortURL="http://....";
String shortURL2="http://....";
String res="";
String mURL=null;
if(Util.isConnectedToServer(shortURL2)){
mURL=url2;
}else{
if(Util.isConnectedToServer(shortURL)) {
mURL = url;
}
}
if(mURL!=null){
String servicestring = Context.DOWNLOAD_SERVICE;
downloadmanager = (DownloadManager) context.getSystemService(servicestring);
for(int i=0;i<urlDownload.size();i++){
FileDownload myFile=urlDownload.get(i);
String filename=myFile.getUrl();
File finalPath=myFile.getFinalPath();
Uri uri = Uri
.parse(mURL + filename.replaceAll("\\+", "%20"));
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setVisibleInDownloadsUi(true);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
request.setTitle(myFile.getName());
request.setDescription("Downloading Resource "+filename);
request.setDestinationUri(Uri.fromFile(finalPath));
downloadmanager.enqueue(request);
}
urlDownload=null;
res="Downloading Resources";
}else{
res="No Connection to Server";
}
return res;
}
}