通知消失-Android DownloadManager

通知消失-Android DownloadManager,android,download,notifications,notify,download-manager,Android,Download,Notifications,Notify,Download Manager,解决方案:需要API 11,请参见下面的答案 简单问题:使用已实现的DownloadManager下载文件后,通知将消失。下载后如何强制保留通知 我尝试使用可见性\u VISIBLE\u NOTIFY\u已完成,但我不知道如何使用它 感谢您为解决此问题提供的任何帮助;) 编辑:代码 public class BgDL extends Activity { private DownloadManager mgr = null; private long id; /** Called when

解决方案:需要API 11,请参见下面的答案

简单问题:使用已实现的DownloadManager下载文件后,通知将消失。下载后如何强制保留通知

我尝试使用可见性\u VISIBLE\u NOTIFY\u已完成,但我不知道如何使用它

感谢您为解决此问题提供的任何帮助;)

编辑:代码

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);
        }
      }


}; 

}在请求中添加正确的标志:

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

request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
参考:

控制下载管理器在下载运行时或下载完成时是否发布系统通知。如果启用,下载管理器将通过系统NotificationManager发布有关下载的通知。默认情况下,仅当下载正在进行时才会显示通知

此下载在进行中和完成后可见并显示在通知中


请发布一些代码,以关闭。Thnx@malger,你解决了这个问题吗?我的通知也消失了。谢谢你的帮助,但问题还没有解决!我得到:“VISIBILITY\u VISIBLE\u NOTIFY\u COMPLETED无法解析或不是字段,但我已经导入了它:“import android.app.DownloadManager;import android.app.DownloadManager.Request;”它需要一个minSdk 11,你可能得到了9?(在您的AndroidManifest中)我链接的API url:“
自:API级别11
”ohh。。。。。这似乎是问题所在。但在姜饼API 9下,我能做些什么来完成这项工作呢?有什么解决办法吗?没有,我想你们错了。在早期的设备上,您必须使用
Request.setShowRunningNotification(true)
以显示下载通知。就在文件里。