0
我已經使用通知來顯示下載文件的狀態。我只是簡單地使用FileOutputStream來下載文件,以便它可以在小於9的API上工作。但現在我的問題是在完成下載之後,我試圖在相應的閱讀器中打開該文件。但它會拋出窗口異常泄露如果我關閉了應用程序,在下載文件之間。通知完成後打開下載文件
我的進度更新方法代碼如下,請幫我出來。
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
progressUpdate(values[0]);
}
@SuppressWarnings("deprecation")
public void progressUpdate(int percentageComplete) {
CharSequence contentText = percentageComplete + "% complete";
mNotification.setLatestEventInfo(mContext, mContentTitle, contentText,
mContentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
if(percentageComplete==100){
try {
Log.e("file path ",file.getAbsolutePath());
Uri path = Uri.fromFile(file);
notificationIntent.setDataAndType(path, "application/pdf");
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(notificationIntent);
finish();
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(),
"Unable to open file ,PDF Reader application is not installed in your device", Toast.LENGTH_SHORT).show();
}
}
}
當活動完成時,Android發出了windowlink錯誤,並且您希望打開對話框或任何視圖提供程序想要附加到窗口。 – nurisezgin