Saturday 15 August 2015

pdf - Android Download Manager can't open file even with correct MIME -



pdf - Android Download Manager can't open file even with correct MIME -

i've simple (so speak) issue android's default download manager.

i download books (i.e. pdf, epub...) using default download manager can't open them if set right mime.

what i'm doing:

string mime = null; mime = getmimefromfilename(file.getname()); if (mime != null) { log.d("dbg", "mime: " + mime); // when dealing pdf prints "mime: application/pdf" request.setmimetype(mime); // i'm overwriting content-type field , log i'm sure mime type right one! } mainactivity.downloadmanager.enqueue(request);

where getmimefromfilename following:

public static string getmimefromfilename(string file) { string mime = null; if (file.lastindexof(".") != -1) { string ext = file.substring(file.lastindexof(".") + 1); mimetypemap mimetype = mimetypemap.getsingleton(); mime = mimetype.getmimetypefromextension(ext); // next mime types not included in mimetypemap class i'll add together them manually if (ext.tolowercase(locale.italy).equals("lit")) mime = "application/x-ms-reader"; if (ext.tolowercase(locale.italy).equals("epub")) mime = "application/epub+zip"; if (ext.tolowercase(locale.italy).equals("mobi")) mime = "application/x-mobipocket-ebook"; } homecoming mime; }

now, here comes unusual thing: if open file in way;

intent intent = new intent(); intent.setaction(android.content.intent.action_view); intent.setdataandtype(path_to_file, mime); context.startactivity(intent);

it works expected, while if in download manager ("download" app) tap downloaded file says "can't open file".

moreover if install app "aldiko", if start intent pdf file opens aldiko , works; while if tap on file's entry within download manager still opens aldiko says "not supported content". epub file works intent while says "can't open file" download manager.

any clues? in advance.

*********************************************edit:***************************************************

things getting weird.

i've tried open pdf file through app (intent) , through android download manager ("download" app). i've next pdf reader installed , when click either in app or in download manager on pdf file shows dialog have take 1 of them.

-adobe reader (works through intent & download manager) -officesuite (works through intent & download manager) -pdf reader (works through intent & download manager) -pdf viewer (works through intent & download manager) -wps office (works through intent & download manager) -aldiko (works through intent not through download manager) -ubr (works through intent not through download manager)

looking @ logcat, i've found different messages using aldiko:

-this 1 when (correctly) opens file using intent

i/activitymanager(569): start u0 {act=android.intent.action.view dat=file:///storage/sdcard0/myapp/books/mypdffile.pdf typ=application/pdf flg=0x3000000 cmp=com.aldiko.android/.ui.aliasimportactivity} pid 8979

-this 1 when (fails to) open file tapping on download manager item:

i/activitymanager(569): start u0 {act=android.intent.action.view dat=content://downloads/all_downloads/25 typ=application/pdf flg=0x3000003 cmp=com.aldiko.android/.ui.aliasimportactivity} pid 8979

try re-setting chrome app (clear defaults / data). worked me.

android pdf android-intent mime android-download-manager

No comments:

Post a Comment