第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

通知欄里面點(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)題?

正在回答

0 回答

舉報(bào)

0/150
提交
取消
Android-Service系列之Notification綜合應(yīng)用
  • 參與學(xué)習(xí)       17288    人
  • 解答問(wèn)題       19    個(gè)

掌握Notification和Messenger機(jī)制,實(shí)現(xiàn)Notification經(jīng)典應(yīng)用場(chǎng)景

進(jìn)入課程

通知欄里面點(diǎn)擊開(kāi)始、暫停按鈕無(wú)效

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)