通知栏里面点击开始、暂停按钮无效
在Notification中点击两个按钮发现无效,并不能做出正确的响应
public void showNotification(FileInfo fileInfo) {
//判断通知是否已经显示
if (mapNotification.containsKey(fileInfo.getId())) {
return;
}
//创建一个通知对象
Notification notification = new Notification();
//设置滚动文字
notification.tickerText = fileInfo.getFileName() + "开始下载";
//设置通知显示的时间
notification.when = System.currentTimeMillis();
//设置图标
notification.icon = R.drawable.ic_launcher;
//设置通知特性,点击通知之后自动消失
notification.flags = Notification.FLAG_AUTO_CANCEL;
//设置点击通知栏的操作
Intent intent = new Intent(context, DownServiceActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
notification.contentIntent = pi;//点击通知栏之后的操作
//创建RemoteViews对象
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.downservice_notification);
//设置TextVie里面的值
remoteViews.setTextViewText(R.id.downNfTvFileName, fileInfo.getFileName());
//设置开始按钮操作
Intent intentStart = new Intent(context, DownService.class);
intentStart.setAction(DownService.ACTION_PREPARE);
intentStart.putExtra(DownService.DOWNINFO, fileInfo);
intentStart.putExtra("value", "start down");
PendingIntent piStart = PendingIntent.getService(context, 0, intentStart, 0);
remoteViews.setOnClickPendingIntent(R.id.downNfBtBegin, piStart);
//设置暂停按钮操作
Intent intentPause = new Intent(context, DownService.class);
intentPause.setAction(DownService.ACTION_PAUSE);
intentPause.putExtra(DownService.DOWNINFO, fileInfo);
intentPause.putExtra("value", "pause down");
PendingIntent piPause = PendingIntent.getService(context, 0, intentPause, 0);
remoteViews.setOnClickPendingIntent(R.id.downNfBtPause, piPause);
//设置Notification的视图
notification.contentView = remoteViews;
//发出通知显示在通知栏
notificationManager.notify(fileInfo.getId(), notification);
//把通知加入到集合中
mapNotification.put(fileInfo.getId(), notification);
}
而且在service的onStartCommand()方法里面取不到intent中value的值,是否代码有问题?