.jpg等其他格式的文件可以下载xlsx格式 每次只是提供错误消息失败时无法下载 下载xslx类型格式。为该错误提供任何解决方案。
这是我的代码
$date1 = new DateTime("2017-05-14");
$date2 = new DateTime("2017-06-14");
$interval = $date1->diff($date2);
$week = floor($date1->diff($date2)->days/7);
echo $week;
if($week > 4)
{
echo $interval->m.' '.($interval->m > 1 ? 'months' : 'month');
}
这是错误日志
public void run() {
// Do stuff
int dl_progress = 0;
try {
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(downloadIds[serial]);
Cursor c = mgr.query(q);
c.moveToFirst();
long bytes_downloaded = c
.getInt(c
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
long bytes_total = c
.getInt(c
.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
if (bytes_total == -1)
dl_progress = 0;
else
dl_progress = (int) ((bytes_downloaded * 100) /
bytes_total);
prefs.edit().putInt(name_of_da + "progress", dl_progress)
.commit();
switch (c.getInt(c
.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
case DownloadManager.STATUS_FAILED:
prefs.edit().putBoolean(name_of_da + "downloading",
false)
.commit();
Toast.makeText(getBaseContext(), "Failed!",
Toast.LENGTH_SHORT).show();
prefs.edit().putBoolean(name_of_da + "downloading",
false)
.commit();
sendBroadcast(new Intent("refresh_downloads"));
this.cancel();
sendNotification(1, serial, name_of_da, dl_progress);
this.cancel();
countOfCurrent--;
if (countOfCurrent == 0)
stopSelf();
// }
break;
case DownloadManager.STATUS_PAUSED:
// msg = "Download paused!";
if (c.getInt(c
.getColumnIndex(DownloadManager.COLUMN_REASON)) ==
DownloadManager.PAUSED_WAITING_FOR_NETWORK) {
if (errorFlag) {
errorFlag = false;
sendNotification(15, serial, name_of_da,
dl_progress);
}
} else {
sendNotification(1, serial, name_of_da,
dl_progress);
this.cancel();
countOfCurrent--;
if (countOfCurrent == 0)
stopSelf();
}
break;
case DownloadManager.STATUS_PENDING:
// msg = "Download pending!";
sendNotification(0, serial, name_of_da, dl_progress);
break;
case DownloadManager.STATUS_RUNNING:
// msg = "Download in progress!";
errorFlag = true;
if (startFlag) {
if (verifyFromSD(name_of_da)) {
startFlag = false;
sendBroadcast(new
Intent("refresh_downloads"));
}
}
if (dl_progress != prevProgr) {
sendNotification(0, serial, name_of_da,
dl_progress);
prevProgr = dl_progress;
}
break;
case DownloadManager.STATUS_SUCCESSFUL:
// msg = "Download complete!";
prefs.edit().putInt(name_of_da, 100).commit();
prefs.edit().putBoolean(name_of_da + "downloading",
false)
.commit();
prefs.edit().putBoolean(name_of_da + "downloaded",
true)
.commit();
prefs.edit()
.putString(
name_of_da + "filepath",
Environment.getExternalStorageDirectory()
.toString()
+ "/Download/"
+ name_of_da).commit();
sendNotification(0, serial, name_of_da, dl_progress); //
Toast.makeText(getBaseContext(), "Download complete: " //
+ Environment.getExternalStorageDirectory().toString() +
"/Download/" + name_of_da // ,
Toast.LENGTH_LONG).show();
this.cancel();
countOfCurrent--;
if (countOfCurrent == 0)
stopSelf();
break;
default:
// msg = "Download is nowhere in sight";
sendNotification(10, serial, name_of_da, dl_progress);
this.cancel();
countOfCurrent--;
if (countOfCurrent == 0)
stopSelf();
break;
}
c.close();
} catch (Exception e) {
e.printStackTrace();
sendNotification(7, serial, name_of_da, dl_progress);
cancel();
countOfCurrent--;
if (countOfCurrent == 0)
stopSelf();
}
}
}
public void sendNotification(int tmout, int nin, String name, int
progress) {
if (tmout == 0) {
if (progress >= 100) {
mBuilder.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_ibt_notification
: R.drawable.ic_ibt_notification)
.setContentTitle("Completed").setContentText(name)
.setOngoing(false).setProgress(100, 100, false);
Uri ttt = Uri.parse("file://"
+ Environment.getExternalStorageDirectory().toString()
+ "/Download/" + name);
Intent intent = new Intent(Intent.ACTION_VIEW);
String arr[] = name.split("\\.");
MimeTypeMap myMime = MimeTypeMap.getSingleton();
String mimeType = myMime
.getMimeTypeFromExtension(arr[arr.length - 1]);
intent.setDataAndType(ttt, mimeType);
prefs.edit().putInt("retry", 1).commit();
PendingIntent i = PendingIntent.getActivity(getBaseContext(),
0, intent, 0);
mBuilder.setContentIntent(i);
notificationManager.notify(nin, mBuilder.build());
} else {
mBuilder.setContentTitle("Downloading: " + name)
.setContentText(progress + " %")
.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_ibt_notification
: R.drawable.ic_ibt_notification)
.setAutoCancel(false).setOngoing(true);
mBuilder.setProgress(100, progress, false);
notificationManager.notify(nin, mBuilder.build());
}
} else {
if (tmout == 1) {
mBuilder.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_abc_notification
: R.drawable.ic_abc_notification)
.setContentTitle("Failed: " + name)
.setContentText(progress + " %").setAutoCancel(true)
.setProgress(100, progress, false).setOngoing(false);
// Intent intnt = new Intent(Mp3Constants.NOTIFICATION);
// intnt.putExtra("resume", "1");
// intnt.putExtra("url", urlD);
// intnt.putExtra("name", name);
// intnt.putExtra("nin", nin);
// PendingIntent i = PendingIntent
// .getBroadcast(conte, 0, intnt, 0);
// mBuilder.setContentIntent(i);
} else if (tmout == 7) {
mBuilder.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_ibt_notification
: R.drawable.ic_ibt_notification)
.setContentTitle("Cancelled: " + name)
.setAutoCancel(true).setProgress(100, progress, false)
.setOngoing(false);
// Intent intnt = new Intent(Mp3Constants.NOTIFICATION);
// intnt.putExtra("resume", "1");
// intnt.putExtra("url", urlD);
// intnt.putExtra("name", name);
// intnt.putExtra("nin", nin);
// PendingIntent i = PendingIntent
// .getBroadcast(conte, 0, intnt, 0);
// mBuilder.setContentIntent(i);
} else if (tmout == 15) {
mBuilder.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_ibt_notification
: R.drawable.ic_ibt_notification)
.setContentTitle("Paused: " + name)
.setContentText("Waiting for network...")
.setAutoCancel(true).setProgress(100, progress, false)
.setOngoing(false);
} else {
mBuilder.setSmallIcon(
getResources().getBoolean(R.bool.isTablet) ?
R.drawable.ic_ibt_notification
: R.drawable.ic_ibt_notification)
.setContentTitle("Interrupted: " + name)
.setContentText("No storage
found").setAutoCancel(true)
.setOngoing(false);
}
notificationManager.notify(nin, mBuilder.build());
}
}
这是Toast,错误日志上的错误跳转单击
Toast.makeText(getBaseContext(),“失败!”