在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使用
//声明
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使用