2012-03-13 32 views
9

Ứng dụng của tôi tải xuống các tệp zip lớn (100mb +). Tôi đang sử dụng Trình quản lý tải xuống mặc định để tạo điều kiện tải xuống. Tài liệu Google API đề xuất đăng ký BroadcastReceiver và lắng nghe ACTION_NOTIFICATION_CLICKED. Tôi đang làm điều đó, nhưng tôi không có đầu mối làm thế nào để gọi cho DownloadManager từ bên trong BroadcastReceiver.Làm cách nào để khởi chạy trình quản lý tải xuống từ Broadcast Receiver?

Điều tôi muốn làm là về cơ bản những gì trình duyệt thực hiện. Khi trình duyệt tải xuống một tệp và người dùng nhấp vào thông báo DownloadManager, cửa sổ DownloadManager sẽ bật lên. Tôi sử dụng mục đích gì để thực hiện điều này?

Mã của tôi:

<receiver android:name="com.test.receiver.DownloadReceiver"> 
    <intent-filter> 
    <action android:name="android.intent.action.DOWNLOAD_COMPLETE"></action> 
    <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" /> 
    </intent-filter> 
</receiver> 

public class DownloadReceiver extends BroadcastReceiver { 

private static final String tag = DownloadReceiver.class.getSimpleName(); 

@Override 
public void onReceive(Context context, Intent intent) { 
    String action = intent.getAction(); 
    if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { 
    *** code for unzipping removed *** 
    } 
    else if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) { 
     // Open the download manager 
     // BUT HOW??? 

    } 

Trả lời

19

Tìm thấy câu trả lời của riêng tôi. Điều này làm các trick.

Intent dm = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); 
dm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(dm); 
Các vấn đề liên quan