Android中notification的使用 【基于Mars-droid的MP3项目的notification使用】

在DownloadService添加以下代码:
//声明
NotificationManager  notification Manager=null;
Notification  notification  = null;

//onStartCommand函数中添加:

notification Manager= (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
notification =new Notification();
//设置显示图标
notification .icon = android.R.drawable.stat_notify_chat;        
//显示时间
notification .when = System.currentTimeMillis();   
// notification .flags = Notification.FLAG_ONGOING_EVENT;

//获得PendingIntent
PendingIntent pi = PendingIntent.getActivity(DownloadService.this, 0, intent, 0);
//设置事件信息,显示在拉开的里面
notification .setLatestEventInfo(DownloadService.this, "Mp3Player", "下载状态", pi);
                 

//run()修改以下代码:
String mp3Url = AppConstant.URL.BASE_URL + URLEncoder.encode(mp3Info.getMp3Name(),"utf-8");                
String lrcUrl = AppConstant.URL.BASE_URL + URLEncoder.encode(mp3Info.getLrcName(),"utf-8");        

//生成下载文件所用的对象
HttpDownloader httpDownloader = new HttpDownloader();
//将文件下载下来,并存储到SDCard当中
int mp3Result = httpDownloader.downFile(mp3Url, "mp3/", mp3Info.getMp3Name());
int lrcResult = httpDownloader.downFile(lrcUrl, "mp3/", mp3Info.getLrcName());
                        
  String resultMessage = "";
  if(mp3Result == -1){
        resultMessage = resultMessage + " 下载失败  ";
  }
  else if(mp3Result == 1){
        resultMessage =  resultMessage + " 已经存在,不需要重复下载   ";
  }
  else if(mp3Result == 0){
        resultMessage =  resultMessage + " 下载成功    ";
  }
                        
  if(lrcResult == -1){
        resultMessage = resultMessage +  " Lrc下载失败    ";
                        }
  else if(lrcResult == 1){
        resultMessage =  resultMessage + " Lrc已经存在,不需要重复下载    ";
                        }
  else if(lrcResult == 0){
        resultMessage =  resultMessage + " Lrc文件下载成功    ";
                        }
  //使用Notification提示客户下载结果
   notification .tickerText = mp3Info.getMp3Name() + resultMessage;
    notification Manager.notify(0,  notification );//这行报                  基于Mars-droid的MP3项目的notification使用 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值