2012-06-20 14 views
9

Soluzione: è necessario l'API 11 vedere la risposta in basso!scompare - Android DownloadManager

Domanda facile: dopo aver scaricato un file con il DownloadManager implementato, la notifica scompare. Come posso forzare la notifica a rimanere dopo il download?

ho provato ad usare VISIBILITY_VISIBLE_NOTIFY_COMPLETED, ma non so come posso usarlo

Grazie per qualsiasi tipo di aiuto per risolvere questo problema;)

EDIT: Codice

public class BgDL extends Activity { 

private DownloadManager mgr = null; 
private long id; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.main); 

    mgr = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 

    Request request = new Request(Uri.parse(getIntent().getStringExtra("URL"))); 

    id = mgr.enqueue(request 
      .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "UPDATE") 
      .setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI|DownloadManager.Request.NETWORK_MOBILE) 
      .setAllowedOverRoaming(false) 
      .setTitle("APP update") 
      .setDescription("New version "+getIntent().getDoubleExtra("OV", 0.0)) 


    ); 

    registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 

} 
BroadcastReceiver receiver = new BroadcastReceiver() { 


     public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     if (action.equals(mgr.ACTION_DOWNLOAD_COMPLETE)){ 
      unregisterReceiver(receiver); 
      finishActivity(99); 
     } 
     } 


}; 

}

+1

Plz invia un codice per uscire. Thnx – CelticParser

+0

Anche quale API usi? –

+0

@malger, sei riuscito a risolvere questo? Anche la mia notifica scompare. –

risposta

21

aggiungere il flag corretto per la vostra richiesta:

Request request = new Request(Uri.parse(getIntent().getStringExtra("URL"))); 

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 

Riferimento:

http://developer.android.com/reference/android/app/DownloadManager.Request.html#setNotificationVisibility(int)

controllo se una notifica di sistema è pubblicato dal gestore di download, mentre il download è in funzione o quando è completato. Se abilitato, il gestore download pubblica notifiche relative ai download tramite il sistema NotificationManager. Per impostazione predefinita, una notifica viene visualizzata solo quando il download è in corso.

http://developer.android.com/reference/android/app/DownloadManager.Request.html#VISIBILITY_VISIBLE_NOTIFY_COMPLETED

Questo download è visibile e mostra nelle notifiche, mentre in corso e dopo il completamento.

+0

grazie per l'aiuto, ma il problema non è ancora risolto! Ottengo: 'VISIBILITY_VISIBLE_NOTIFY_COMPLETED non può essere risolto o non è un campo – malger

+0

Devi importarlo come ho mostrato. È collegato all'API – Blundell

+0

ma l'ho importato: " import android.app.DownloadManager; import android.app.DownloadManager.Request;" – malger

Problemi correlati