【发布时间】:2014-12-05 07:34:45
【问题描述】:
目前我有一个通知面板,它有三个按钮。一个用于打开活动,一个用于暂停上传,另一个用于恢复上传。
我希望暂停上传和恢复上传有一个按钮,例如 Google 音乐播放器中的暂停/播放按钮。
我使用this 回答构建通知面板。请推荐!
通知面板类:
public NotificationPanel(Context parent) {
// TODO Auto-generated constructor stub
this.parent = parent;
nBuilder = new NotificationCompat.Builder(parent)
.setContentTitle("Notification Title")
.setSmallIcon(R.drawable.logo)
.setOngoing(true);
remoteView = new RemoteViews(parent.getPackageName(), R.layout.notification_layout);
//set the button listeners
setListeners(remoteView);
nBuilder.setContent(remoteView);
nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(2, nBuilder.build());
}
public void setListeners(RemoteViews view){
Intent stopNotify = new Intent(parent,HelperActivity.class);
stopNotify.putExtra("DO", "stop");
PendingIntent btn1 = PendingIntent.getActivity(parent, 0, stopNotify, 0);
view.setOnClickPendingIntent(R.id.notifyStopButton, btn1);
Intent pauseUpload = new Intent(parent,HelperActivity.class);
pauseUpload.putExtra("DO", "pause");
PendingIntent btn2 = PendingIntent.getActivity(parent, 1, pauseUpload, 0);
view.setOnClickPendingIntent(R.id.uploadPauseButton, btn2);
Intent resumeUpload = new Intent(parent,HelperActivity.class);
resumeUpload.putExtra("DO", "upload");
PendingIntent btn3 = PendingIntent.getActivity(parent, 2, resumeUpload, 0);
view.setOnClickPendingIntent(R.id.uploadResumeButton, btn3);
}
public void notificationCancel() {
nManager.cancel(2);
}
【问题讨论】:
标签: android android-notifications