错误
下载完正要安装时出现弹窗:解析软件包时出现问题
查看Run
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.view.View$OnUnhandledKeyEventListener” on path: DexPathList[[zip file “/data/app/com.example.downapkapplication-1/base.apk”],nativeLibraryDirectories=[/data/app/com.example.downapkapplication-1/lib/x86, /system/lib, /vendor/lib]]
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.View$OnUnhandledKeyEventListener" on path: DexPathList[[zip file "/data/app/com.example.downapkapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.downapkapplication-1/lib/x86, /system/lib, /vendor/lib]]
百度翻译一下如图
大概能看到是在路径上找不到什么(可能),因为是在下载安装apk,所以应该是在安装的位置上没找到需要安装的 .apk文件
解决思路
找到对应下载、安装代码,以及安装的位置进行查看apk
- 下载代码内容:
request.setDestinationInExternalFilesDir(mContext, Environment.DIRECTORY_DOWNLOADS,"Android_8.7.0.5295_537068059.apk");
- 安装代码内容:
installintent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/Android_8.7.0.5295_537068059.apk")),"application/vnd.android.package-archive");
- 位置
Log.i("LXH","setDestinationInExternalFilesDir:"+Environment.DIRECTORY_DOWNLOADS+"/Android_8.7.0.5295_537068059.apk");
显示位置在Download/Android_8.7.0.5295_537068059.apk
- 找到内部存储空间下的Download/ 如图:
- 错误原因分析:
Download/没有发现我们下载的apk文件,但是Log下载显示完成,说明安装路径不应该是Download/里面,所以解析安装会出错
解决办法
- 找到下载的路径:
setDestinationInExternalFilesDir的下载默认是在:SD卡/Android/data/项目包名/file/Download
找到下载的apk文件
- 修改安装路径为对应路径:
installintent.setDataAndType(Uri.fromFile(new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/Android_8.7.0.5295_537068059.apk")),"application/vnd.android.package-archive");
运行成功
显示对应路径,并成功安装
记录
- setDestinationInExternalFilesDir的位置在:/storage/emulated/0/Android/data/包名/files/Download/
查看可以用getExternalFilesDir - setDestinationInExternalPublicDir的位置在:/storage/emulated/0/Download/
欢迎指错,一起学习