Friday, 15 July 2011

android - open file on click of notification? -



android - open file on click of notification? -

i want open file when gets downloaded(using services) services on click of notification.i have passed "http://railsboxtech.com/singing/song/ishq_wala_instrument.mp3" url in mainactivity downloading it. using next code:

public class downloadservice extends intentservice { string urlpath; private int result = activity.result_canceled; public downloadservice() { super("downloadservice"); } // called asynchronously android @override protected void onhandleintent(intent intent) { uri info = intent.getdata(); urlpath = intent.getstringextra("urlpath"); string filename = data.getlastpathsegment(); file output = new file(environment.getexternalstoragedirectory(), filename); if (output.exists()) { output.delete(); } inputstream stream = null; fileoutputstream fos = null; seek { url url = new url(urlpath); stream = url.openconnection().getinputstream(); inputstreamreader reader = new inputstreamreader(stream); fos = new fileoutputstream(output.getpath()); int next = -1; while ((next = reader.read()) != -1) { fos.write(next); } // sucessful finished result = activity.result_ok; } grab (exception e) { e.printstacktrace(); } { if (stream != null) { seek { stream.close(); } grab (ioexception e) { e.printstacktrace(); } } if (fos != null) { seek { fos.close(); } grab (ioexception e) { e.printstacktrace(); } } } bundle extras = intent.getextras(); if (extras != null) { messenger messenger = (messenger) extras.get("messenger"); message msg = message.obtain(); msg.arg1 = result; msg.obj = output.getabsolutepath(); intent intent1 = new intent(intent.action_view, uri.parse("file://"+msg.obj)); taskstackbuilder stackbuilder = taskstackbuilder .create(downloadservice.this); stackbuilder.addparentstack(mainactivity.class); stackbuilder.addnextintent(intent1); final pendingintent resultpendingintent = stackbuilder.getpendingintent(0, pendingintent.flag_update_current); notificationcompat.builder mbuilder = new notificationcompat.builder( downloadservice.this) .setcontenttitle("file downloaded") .setcontenttext("isq_wala_love.mp3").setsmallicon(r.drawable.ic_launcher) .setcontentintent(resultpendingintent) .addaction(r.drawable.ic_launcher, "call", resultpendingintent); mbuilder.setcontentintent(resultpendingintent); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.notify(0, mbuilder.build()); seek { messenger.send(msg); } grab (android.os.remoteexception e1) { log.w(getclass().getname(), "exception sending message", e1); } } } }

but it's not able open file location.

set intent dataandtypeas follow:

intent.setdataandtype(uri.fromfile(file), "whatevermimetype");

android

No comments:

Post a Comment