当我尝试在5个不同的手机上安装apk时,其中一个会发生恐慌。其他4个工作正常。这是错误信息:
android.content.pm.PackageParser $ PackageParserException:添加资产路径失败
java.lang.SecurityException:getDeviceId:用户10071和当前进程都没有android.permission.READ_PHONE_STATE
以下是详细错误:
04-07 12:10:06.788 9371-9371/? W/zipro: Error opening archive /storage/6365-3066/Download/qqmail/ISCAN-debug.apk: Invalid file
04-07 12:10:06.789 9371-9371/? E/PackageUtil: can not parse packag
android.content.pm.PackageParser$PackageParserException: Failed adding asset path: /storage/6365-3066/Download/qqmail/ISCAN-debug.apk
at android.content.pm.PackageParser.loadApkIntoAssetManager(PackageParser.java:898)
at android.content.pm.PackageParser.parseBaseApk(PackageParser.java:926)
at android.content.pm.PackageParser.parseMonolithicPackage(PackageParser.java:874)
at android.content.pm.PackageParser.parseMonolithicPackage(PackageParser.java:855)
at com.android.packageinstaller.PackageUtil.getPackageInfo(PackageUtil.java:79)
at com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:728)
at android.app.Activity.performCreate(Activity.java:6367)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:682)
04-07 12:10:06.789 9371-9371/? W/PackageInstaller: Parse error when parsing manifest. Discontinuing installation
04-07 12:10:06.794 3635-3635/? I/WindowBlurViewManager: allowChangeBlurBackground
04-07 12:10:06.818 4402-4163/? W/System.err: java.lang.SecurityException: getDeviceId: Neither user 10071 nor current process has android.permission.READ_PHONE_STATE.
04-07 12:10:06.818 4402-4163/? W/System.err: at android.app.ContextImpl.enforce(ContextImpl.java:1595)
04-07 12:10:06.818 4402-4163/? W/System.err: at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1627)
04-07 12:10:06.818 4402-4163/? W/System.err: at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:675)
04-07 12:10:06.818 4402-4163/? W/System.err: at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:675)
04-07 12:10:06.818 4402-4163/? W/System.err: at com.android.internal.telephony.HwPhoneService.canReadPhoneState(HwPhoneService.java:969)
04-07 12:10:06.818 4402-4163/? W/System.err: at com.android.internal.telephony.HwPhoneService.getUniqueDeviceId(HwPhoneService.java:984)
04-07 12:10:06.818 4402-4163/? W/System.err: at com.android.internal.telephony.IHwTelephony$Stub.onTransact(IHwTelephony.java:364)
04-07 12:10:06.818 4402-4163/? W/System.err: at android.os.Binder.execTransact(Binder.java:453)
04-07 12:10:06.819 9371-9392/? W/System.err: java.lang.SecurityException: getDeviceId: Neither user 10071 nor current process has android.permission.READ_PHONE_STATE.
04-07 12:10:06.819 9371-9392/? W/System.err: at android.os.Parcel.readException(Parcel.java:1602)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.os.Parcel.readException(Parcel.java:1555)
04-07 12:10:06.820 9371-9392/? W/System.err: at com.android.internal.telephony.IHwTelephony$Stub$Proxy.getUniqueDeviceId(IHwTelephony.java:1297)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.telephony.HwTelephonyManagerInner.getUniqueDeviceId(HwTelephonyManagerInner.java:843)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.telephony.HwInnerTelephonyManagerImpl.getUniqueDeviceId(HwInnerTelephonyManagerImpl.java:340)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:723)
04-07 12:10:06.820 9371-9392/? W/System.err: at com.hianalytics.android.v1.e.a(Unknown Source)
04-07 12:10:06.820 9371-9392/? W/System.err: at com.hianalytics.android.v1.e.run(Unknown Source)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.os.Handler.handleCallback(Handler.java:743)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.os.Looper.loop(Looper.java:150)
04-07 12:10:06.820 9371-9392/? W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
知道为什么它只发生在那部手机上?怎么解决?谢谢。
答案 0 :(得分:0)
04-07 12:10:06.788 9371-9371 /? W / zipro:打开存档时出错 /storage/6365-3066/Download/qqmail/ISCAN-debug.apk:文件无效
这就是问题所在。
根据Android source,在几个地方报告了kInvalidFile
的返回代码:
我的猜测是,在/storage/...
位置访问APK时出现了问题。尝试将APK移动到正常的Android临时目录 - /data/local/tmp/
。
如果不这样做,那么APK本身或某些其他软件(防病毒,反恶意软件等)的某些损坏就会阻止文件被访问。
答案 1 :(得分:0)
这是因为也许你不会自己批准棉花糖...试试这个:
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.READ_PHONE_STATE},
1);
或在你的oncreate上使用它:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED){
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},100);
return;
}
}
然后使用此方法:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if(requestCode == 100 && (grantResults[0] == PackageManager.PERMISSION_GRANTED)){
pick_file();
}else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},100);
}
}
}