亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

通知欄里面點擊開始、暫停按鈕無效

在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的值,是否代碼有問題?

正在回答

0 回答

舉報

0/150
提交
取消
Android-Service系列之Notification綜合應用
  • 參與學習       17288    人
  • 解答問題       19    個

掌握Notification和Messenger機制,實現Notification經典應用場景

進入課程

通知欄里面點擊開始、暫停按鈕無效

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號