WEB开发网
开发学院手机开发Android 开发 Android通过AIDL实现下载进程通信 阅读

Android通过AIDL实现下载进程通信

 2012-11-08 19:04:01 来源:WEB开发网   
核心提示:notify.flags = Notification.FLAG_AUTO_CANCEL;notify.icon = android.R.drawable.stat_notify_error;notify.contentView.setImageViewResource(R.id.downloadImg, androi
notify.flags = Notification.FLAG_AUTO_CANCEL;
notify.icon = android.R.drawable.stat_notify_error;
notify.contentView.setImageViewResource(R.id.downloadImg, android.R.drawable.stat_sys_warning);
notify.contentView.setTextViewText(R.id.percetText, "发生异常,停止下载");
notify.contentView.setTextColor(R.id.downloadText, Color.RED);
notify.contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0,
new Intent(DownLoadService.this,DownLoadService.class),
PendingIntent.FLAG_UPDATE_CURRENT);
nManager.notify(notifi_id, notify);
break;
}
super.handleMessage(msg);
}
};

/**
* 创建一个新notify
* @param String tickText 显示在进度条上的文字标题
* @param Intent intent 绑定的intent
* @param int flag notification标识:是否可以被自动清除
* @param int progressMax 最大进度条刻度
**/
private Notification newNotification(String tickText, Intent intent,
int flag, int progressMax) {
Notification notification = new Notification(
android.R.drawable.stat_sys_download, tickText, System
.currentTimeMillis());
notification.flags = flag;
notification.contentView = new RemoteViews(getPackageName(),
R.layout.download_progress);
notification.contentView.setProgressBar(R.id.downloadProgress,
progressMax, 0, false);
notification.contentView.setTextViewText(R.id.downloadText, tickText);

final Context cxt = getApplicationContext();
PendingIntent contentIntent = PendingIntent.getActivity(cxt, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = contentIntent;
return notification;
}

//IDownLoadService接口的实现,该接口提供对外访问接口
IDownLoadService.Stub mBinder = new IDownLoadService.Stub() {

@Override
public boolean isDownLoading(int id) throws RemoteException {
// 是否正则下载,客户端可以根据此方法避免重复下载
if(queueList.containsKey(id) && !queueList.get(id).isCancel()){
return true;
}
return false;
}

@Override
public List<Queue> getQueueList() throws RemoteException {
//获取下载队列,客户端通过该方法获取当前下载队列信息,结合cancelQueue,可以实现取消下载
List<Queue> list = new ArrayList<Queue>();
for (Iterator<Entry<Integer, Queue>> it = queueList.entrySet().iterator(); it.hasNext();){
Entry<Integer, Queue> entry = it.next();
if(!entry.getValue().isCancel()){
list.add(entry.getValue());
}
}
return list;
}

@Override
public void cancelQueue(int id) throws RemoteException {
// 取消下载
if(queueList.containsKey(id)){
queueList.get(id).setCancel(true);
}
}
};

@Override

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Android 通过 AIDL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接