2012-06-20 29 views
9

Giải pháp: API 11 là cần thiết xem câu trả lời bên dưới!thông báo biến mất - Android DownloadManager

Câu hỏi dễ dàng: Sau khi tải xuống tệp có tệp DownloadManager được triển khai, Thông báo sẽ biến mất. Làm cách nào để buộc Thông báo ở lại sau khi Tải xuống?

Tôi cố gắng để sử dụng VISIBILITY_VISIBLE_NOTIFY_COMPLETED, nhưng tôi không biết làm thế nào tôi có thể sử dụng nó

Thank cho bất kỳ loại giúp đỡ để giải quyết vấn đề này;)

EDIT: Mã

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 đăng một số mã để tắt. Thnx – CelticParser

+0

Bạn cũng sử dụng API nào? –

+0

@malger, bạn có quản lý để giải quyết vấn đề này không? Thông báo của tôi cũng biến mất. –

Trả lời

21

Thêm cờ chính xác vào yêu cầu của bạn:

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

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 

tham khảo:

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

Kiểm soát việc thông báo hệ thống được đăng tải bởi các quản lý download khi tải này đang chạy hoặc khi nó được hoàn thành. Nếu được bật, trình quản lý tải xuống sẽ đăng thông báo về các bản tải xuống thông qua NotificationManager của hệ thống. Theo mặc định, thông báo chỉ được hiển thị khi đang tải xuống.

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

tải này có thể nhìn thấy và chỉ ra trong thông báo trong khi tiến hành và sau khi hoàn thành.

+0

cảm ơn bạn đã trợ giúp, nhưng vấn đề vẫn chưa được giải quyết! Tôi nhận được: 'VISIBILITY_VISIBLE_NOTIFY_COMPLETED không thể được giải quyết hoặc không phải là trường – malger

+0

Bạn phải nhập nó như tôi đã hiển thị. Nó được liên kết trong API – Blundell

+0

nhưng tôi đã nhập nó: " nhập android.app.DownloadManager; nhập android.app.DownloadManager.Request;" – malger

Các vấn đề liên quan