android - How to browse to destination folder when clicking on download notification -


from app, downloading music files , saving them in folder. in notification panel download progress shown. when download completes, if notification clicked, android device should directly browse destination folder, similar "go folder" on pcs after download finishes.

i tried below code, not working. opening app.

public class temp extends activity {      string[] link;     string[] items;     string song_link;     string song_name;     int song_index;     int link_index;     string url_link;     exception error;     private progressbar mprogress;     long total = 0;     boolean downloadstatus = false;     progressdialog progressbar;       private handler progressbarhandler = new handler();       int progressbarstatus = 0;      uri selecteduri;     intent intent;     pendingintent resultpendingintent;        notificationcompat.builder mbuilder=              new notificationcompat.builder(this)             .setsmallicon(r.drawable.ic_launcher)             .setcontenttitle("my notification")             .setcontenttext("downloading");     notificationmanager mnotificationmanager;      int id=1;       private class downloadfilestask extends asynctask<string, integer, long> {          protected long doinbackground(string... urls) {              mnotificationmanager =                 (notificationmanager) getsystemservice(context.notification_service);             // mprogress = (progressbar) findviewbyid(r.id.progress_bar);              url_link = urls[0];                  try {                     /* runonuithread(new runnable() {                         public void run() {                              toast.maketext(getapplicationcontext(),"link: "+url_link,toast.length_short).show();                          }                     });*/                      int count;                      url url = new url(url_link);                     urlconnection conexion = url.openconnection();                     conexion.connect();                     // useful can show typical 0-100% progress bar                     final int lenghtoffile = conexion.getcontentlength();                      // download file                     inputstream input = new bufferedinputstream(url.openstream());                    // string name = "first.mp3";                           file folder = new file(environment.getexternalstoragepublicdirectory(                                     environment.directory_music), "vaishnav songs");                             if (!folder.mkdirs()) {                                 log.e(download_service, "directory not created");                             }                           file filename = new file(folder,song_name);                          outputstream output = null;                               output = new bufferedoutputstream(new fileoutputstream(filename));                      byte data[] = new byte[1024];                     mbuilder.setcontenttitle(song_name);                   int percentage;                   id = song_index*10 + link_index;                     while ((count = input.read(data)) != -1) {                         total += count;                         // publishing progress....                      //  publishprogress((int)(total*100/lenghtoffile) );                         percentage = (int)(total*100/lenghtoffile) ;                         if(percentage%5 ==0){                            new thread(new runnable() {                               public void run() {                                  mbuilder.setprogress(100, (int)total*100/lenghtoffile, false);                                 // displays progress bar first time.                                 mnotificationmanager.notify(id, mbuilder.build());                                }                           }).start();                         }                            output.write(data, 0, count);                     }                      output.flush();                     output.close();                     input.close();                     mbuilder.setcontentintent(resultpendingintent);                    new thread(new runnable() {                       public void run() {                          mbuilder.setcontenttext("download complete")                         // removes progress bar                                 .setprogress(100,100,false);                         mnotificationmanager.notify(id, mbuilder.build());                        }                   }).start();                         }                      catch (exception e) {                         error = e;                          runonuithread(new runnable() {                             public void run() {                                  toast.maketext(getapplicationcontext(),"error: "+error,toast.length_short).show();                              }                         });                     }                       // escape if cancel() called                //  if (iscancelled()) break;                return total;          }           protected void onprogressupdate(integer... progress) {              progressbarstatus = progress[0];              }           protected void onpostexecute(long result) {             /* toast.maketext(getapplicationcontext(),"downloaded "+result+" bytes",toast.length_short).show();*/              intent intent = getintent();              finish();              //startactivity(intent);      }      }      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);           selecteduri = uri.parse(environment.getexternalstoragepublicdirectory(                     environment.directory_music) + "/"+"vaishnav songs"+"/");           intent = new intent(intent.action_view);           intent.setdataandtype(selecteduri, "resource/folder");           resultpendingintent =                 pendingintent.getactivity(                 this,                 0,                 intent,                 pendingintent.flag_update_current             );          song_name = (string) getintent().getextras().getstring("songname");         song_link = (string) getintent().getextras().getstring("songlink");         song_index = getintent().getintextra("songindex",0);         link_index = getintent().getintextra("position",0);          toast.maketext(getapplicationcontext(),"download started. check progress in notification panel",toast.length_short).show();          //new downloadfilestask().execute(song_link);          downloadfilestask task = new downloadfilestask();             task.executeonexecutor(asynctask.thread_pool_executor,song_link);         finish();     } } 

discover https://developer.android.com/reference/android/app/notification.builder.html
can try add setcontentintent(pendingintent intent) notification action file manager opening.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -