android - stand alone broadcast receiver for Download Manager -


i have broadcastreceiver listens download complete action opens file when download completes.

my issue user may download file , minimize screen unregisters broadcastreceiver, file isn't opened automatically when download completes.

how can set stand alone broadcastreceiver image opened when app stopped/destroyed. can't figure out how make listen download complete action.

private broadcastreceiver downloadreceiver = new broadcastreceiver() {      @override     public void onreceive(context context, intent intent) {         long referenceid = intent.getlongextra(downloadmanager.extra_download_id, -1);         if (downloadreference == referenceid) {             downloadmanager.query query = new downloadmanager.query();             query.setfilterbyid(referenceid);             cursor cursor = downloadmanager.query(query);             if (cursor.movetofirst()) {                 int status = cursor.getint(cursor.getcolumnindex(downloadmanager.column_status));                 if (status == downloadmanager.status_successful) {                     intent intentpic = new intent();                     intentpic.setaction(android.content.intent.action_view);                     intentpic.setdataandtype(uri.fromfile(getactivity().getexternalfilesdir("/update/asd.jpg")), "image/*");                     startactivity(intentpic);                     if(receiverregistered) {                         getactivity().unregisterreceiver(downloadreceiver);                     }                 }             }             cursor.close();             log.i(tag, "downloading of data finished");         }     } }; 

you shouldn't start activities when app in background. okay receiver unregistered when user leaves app.

instead, store information image downloaded , check when app resumed. don't know use case, but, example can store information sharedpreferences , check when app resumed. can decide whether start new activity or not.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -