@Override public void onComplete(DownloadTask task) throws RemoteException { // TODO Auto-generated method stub if (task != null) { stopAppGameNetLog(task); String filePath = task.getSaveFilePath(); File saveFile = new File(filePath); if (saveFile.exists() && saveFile.isFile()) { sendBroadcastingToAppCenter(task); } if (mContext != null && mNotificationManager != null) { // 首先移除之前的通知 mNotificationManager.cancel(NOTIFY_TAG, (int) task.getId()); if (mShowNotification) { // 创建新的通知,该通知可清除,点击后自动消失,并且进行安装 Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType( Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive"); intent.setClass(mContext, AppInstallActivity.class); PendingIntent downCompletedIntent = PendingIntent.getActivity(mContext, 0, intent, 0); Notification finishNotification = new Notification( R.drawable.notification_download_complete_icon, mCompletedTickerText, System.currentTimeMillis()); finishNotification.setLatestEventInfo( mContext, task.getDownloadName(), mCompleteText, downCompletedIntent); // 该通知可清除,点击后自动消失 finishNotification.flags = Notification.FLAG_AUTO_CANCEL; // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), finishNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), finishNotification); } } } openFile(task.getSaveFilePath()); } }
@Override public void onStart(DownloadTask task) throws RemoteException { // TODO Auto-generated method stub if (task == null) { // add by zhaojunjie return; } AppGameNetLogControll.getInstance() .startRecord( mContext, AppGameNetLogControll.DEFAULT_CURRENT_THREAD_CODE, AppGameNetInfoLog.NETLOG_TYPE_FOR_DOWNLOAD_APK); AppGameNetLogControll.getInstance() .setUrl(AppGameNetLogControll.DEFAULT_CURRENT_THREAD_CODE, task.getDownloadUrl()); mChildThreadCode = Thread.currentThread().hashCode(); mStartConntion = System.currentTimeMillis(); sendBroadcastingToAppCenter(task); if (mContext != null && mNotificationManager != null) { String downloadName = task.getDownloadName(); if (downloadName != null) { mStartTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_start_text)); mStopTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_stop_text)); mFailTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_fail_text)); mCompletedTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_complete_text)); mCancelTickerText = String.format( DOWNLOAD_TICKER_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_ticker_cancel_text)); mConnectText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_connect_text)); mDownloadText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_download_text)); mPauseText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_pause_text)); mFailText = String.format( DOWNLOAD_INFO_FORMAT_STRING, downloadName, mContext.getString(R.string.appgame_notification_fail_text)); mCompleteText = mContext.getString(R.string.appgame_notification_complete_text); mProgressText = mContext.getString(R.string.appgame_notification_progress_text); Intent intent = new Intent(); intent.setClass(mContext, AppsDownloadActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mPendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification( R.drawable.notification_download_icon, mStartTickerText, System.currentTimeMillis()); mNotification.contentIntent = mPendingIntent; mNotification.flags = Notification.FLAG_AUTO_CANCEL; mNotification.setLatestEventInfo( mContext, mConnectText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } else { mShowNotification = false; } } }