Closed c4jeff closed 5 years ago
这是怎么出现的?DownloadManager 没有初始化
异常设备:
这是我的调用方法:
if (bean == null) return;
int code = bean.getVersionNumber();
if (code <= AppUtils.getAppVersionCode()) { if (showNewerToast) ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.latest_version)); return; }
String name = bean.getVersion(); String desc = bean.getUpdateContext(); int is_force = bean.getForce(); String downloadUrl = bean.getAndroidDownloadUrl();
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AutoSize_AlertDialog) .setTitle(BaseApp.get().getResources().getString(R.string.new_version)) .setMessage(desc) .setCancelable(false) .setPositiveButton(BaseApp.get().getResources().getString(R.string.updatenow), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.getInstance().release(); } catch (Exception e) { e.printStackTrace(); } DownloadManager manager = DownloadManager.getInstance(context); manager.setApkName(name + ".apk") .setApkUrl(downloadUrl.startsWith("http") ? downloadUrl : BaseApp.get().getResources().getString(R.string.baseUrl) + downloadUrl) .setDownloadPath(AppConfig.FILE_PATH) .setSmallIcon(R.mipmap.ic_launcher) .setConfiguration(new UpdateConfiguration().setOnDownloadListener(new OnDownloadListener() { @Override public void start() { ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_start)); }
@Override
public void downloading(int max, int progress) {
}
@Override
public void done(File apk) {
ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_completed));
}
@Override
public void cancel() {
ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_cancel));
}
@Override
public void error(Exception e) {
ApiException exception = ExceptionManager.handleException(e);
String error = exception.toString();
ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_error) + error);
}
}))
.setAuthorities(AppUtils.getAppPackageName() + ".fileProvider")//必须与Manifest中的provider的authorities一致
.download();
}
});
if (is_force != 1) { builder.setNegativeButton(BaseApp.get().getResources().getString(R.string.update_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.getInstance().release(); dialog.cancel(); } catch (Exception e) { e.printStackTrace(); } } }); } builder.create().show();
这样调用没错啊,你这个bug是必现的吗?
偶现的 ,我这边定位不到异常点... 三星那款设备好像是模拟器多开出来的
那就奇怪了
------------------ 原始邮件 ------------------ 发件人: "Jeff Lin"notifications@github.com; 发送时间: 2019年7月11日(星期四) 下午4:14 收件人: "azhon/AppUpdate"AppUpdate@noreply.github.com; 抄送: "阿钟"958460248@qq.com; "Comment"comment@noreply.github.com; 主题: Re: [azhon/AppUpdate] 报错:java.lang.RuntimeException (#44)
偶现的 ,我这边定位不到异常点... 三星那款设备好像是模拟器多开出来的
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
2 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3529) 3 ...... 4 Caused by: 5 java.lang.RuntimeException:请先调用 getInstance(Context context) ! 6 com.azhon.appupdate.manager.DownloadManager.a(TbsSdkJava:113) 7 com.azhon.appupdate.service.DownloadService.init(TbsSdkJava:66) 8 com.azhon.appupdate.service.DownloadService.onStartCommand(TbsSdkJava:60) 9 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3509) 10 android.app.ActivityThread.-wrap20(Unknown Source:0) 11 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1717) 12 android.os.Handler.dispatchMessage(Handler.java:106) 13 android.os.Looper.loop(Looper.java:164) 14 android.app.ActivityThread.main(ActivityThread.java:6648) 15 java.lang.reflect.Method.invoke(Native Method) 16 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 17 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)
正常使用的情况吗。还是怎么操作的?
错误日志: java.lang.RuntimeException:Unable to start service com.azhon.appupdate.service.DownloadService@8e37359 with Intent { hwFlg=0x100 cmp=com.xx.xx/com.azhon.appupdate.service.DownloadService }: java.lang.RuntimeException: 请先调用 getInstance(Context context) !
未在依赖库外调用getInstance()方法