通知欄里面點(diǎn)擊開(kāi)始、暫停按鈕無(wú)效
在Notification中點(diǎn)擊兩個(gè)按鈕發(fā)現(xiàn)無(wú)效,并不能做出正確的響應(yīng)
public void showNotification(FileInfo fileInfo) {
? ?//判斷通知是否已經(jīng)顯示
? ?if (mapNotification.containsKey(fileInfo.getId())) {
? ? ? ?return;
? ?}
? ?//創(chuàng)建一個(gè)通知對(duì)象
? ?Notification notification = new Notification();
? ?//設(shè)置滾動(dòng)文字
? ?notification.tickerText = fileInfo.getFileName() + "開(kāi)始下載";
? ?//設(shè)置通知顯示的時(shí)間
? ?notification.when = System.currentTimeMillis();
? ?//設(shè)置圖標(biāo)
? ?notification.icon = R.drawable.ic_launcher;
? ?//設(shè)置通知特性,點(diǎn)擊通知之后自動(dòng)消失
? ?notification.flags = Notification.FLAG_AUTO_CANCEL;
? ?//設(shè)置點(diǎn)擊通知欄的操作
? ?Intent intent = new Intent(context, DownServiceActivity.class);
? ?PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
? ?notification.contentIntent = pi;//點(diǎn)擊通知欄之后的操作
? ?//創(chuàng)建RemoteViews對(duì)象
? ?RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.downservice_notification);
? ?//設(shè)置TextVie里面的值
? ?remoteViews.setTextViewText(R.id.downNfTvFileName, fileInfo.getFileName());
? ?//設(shè)置開(kāi)始按鈕操作
? ?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);
? ?//設(shè)置暫停按鈕操作
? ?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);
? ?//設(shè)置Notification的視圖
? ?notification.contentView = remoteViews;
? ?//發(fā)出通知顯示在通知欄
? ?notificationManager.notify(fileInfo.getId(), notification);
? ?//把通知加入到集合中
? ?mapNotification.put(fileInfo.getId(), notification);
}
而且在service的onStartCommand()方法里面取不到intent中value的值,是否代碼有問(wèn)題?