android - Determining MIME type of shared Dropbox intent? -
my app receive share requests other apps including dropbox. need know kind of file receiving, mime type dropbox "text/plain". example:
intent = getintent(); string smimetype = i.gettype(); //value = "text/plain" string sextratext = i.getstringextra(intent.extra_text); //value = "http://db.tt/th42k3b7"
i need know difference between images, videos , music files. there way determine file type based on information in intent? or there way use dropbox api this?
thanks, -gregg reno
edit: based on proposed solution smarx, found android code here: android - detect url mime type?. added this:
slocation = connection.getheaderfield("location"); mimetype = urlconnection.guesscontenttypefromname(slocation);
i'm not sure norm here, think text/plain
refers type of data being shared in intent. (because it's url, plain text seems appropriate.)
from url, can find mime type issuing head
request. first resolve shortened link full share link (in location
header). convert share link direct link content replacing www.dropbox.com
dl.dropboxusercontent.com
. (see https://www.dropbox.com/help/201.) issue head
request , take @ content-type
header:
$ http head http://db.tt/th42k3b7 http/1.1 302 found connection: keep-alive content-type: text/html; charset=utf-8 date: mon, 26 aug 2013 15:12:32 gmt server: nginx cache-control: no-cache location: https://www.dropbox.com/s/dmbdlf56t043miq/2012-02-11%2019.56.17.jpg pragma: no-cache $ http head https://dl.dropboxusercontent.com/s/dmbdlf56t043miq/2012-02-11%2019.56.17.jpg http/1.1 200 ok connection: keep-alive content-type: image/jpeg content-length: 1560063 date: mon, 26 aug 2013 15:12:52 gmt server: nginx x-requestid: a2c4d393af5e0eee80d6f33f68762fd4 accept-ranges: bytes cache-control: max-age=0 etag: 1525n pragma: public x-dropbox-request-id: 23f50be73831cde4f39a12d5e3f0af78 x-server-response-time: 1149
(p.s. tool i'm using httpie. same thing curl -i
.)
Comments
Post a Comment