android - DownloadManager doesn't receive download complete action -


i have intent service downloads file in background, broadcast receiver registered listen download completion, never gets in onreceive() function of receiver. file seems finish downloading, can see in file explorer, , message downloadmanager status success. right before download success message i'm getting error failed chmod /mnt/internal_sd/../filedownloaded

intent started main activity oncreate:

intent = new intent(context, myintentservice.class); startservice(i); 

intent service:

public class myintentservice extends intentservice  {      downloadmanager downloadmanager;      @override     protected void onhandleintent(intent intent) {         intentfilter filter = new intentfilter(downloadmanager.action_download_complete);         registerreceiver(downloadreceiver, filter);         downloadfile();     }      void downloadfile(uri downloaduri) {         downloadmanager = (downloadmanager) getsystemservice(download_service);          downloadmanager.request request = new downloadmanager.request(downloaduri);         request.setallowednetworktypes(downloadmanager.request.network_wifi);         request.setallowedoverroaming(false);         request.settitle("my andorid app download");         request.setdestinationinexternalfilesdir(getapplicationcontext(), null, sku + ".apk");          long downloadnum = downloadmanager.enqueue(request);             }      private broadcastreceiver downloadreceiver = new broadcastreceiver() {         @override         public void onreceive(context context, intent intent) {                      system.out.println("does not in here.");             long id = intent.getlongextra(downloadmanager.extra_download_id, 0);             uri u = downloadmanager.geturifordownloadedfile(id);         }     }; } 

manifest:

<service     android:name="com.example.myintentservice"     android:exported="false">      <intent-filter>       <action android:name="android.intent.action.download_complete" />                      </intent-filter>  </service>  

it sounds permissions issue failed chmod error, can't quite figure out what.

i figured out problem. shouldn't have broadcast receiver in intent service, since intent service runs on separate thread execute in onhandleintent() go away. intent service gone before download manager broadcast download completion.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -