首页 > 解决方案 > 通过 USB 和包安装程序更新 Android Things 应用程序

问题描述

由于 Android Things 控制台于 2022 年关闭,我想知道你们中是否有人尝试通过 USB 更新应用程序。

我试过没有成功:

第一次尝试:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", layoutPath), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);

结果:由于 MANAGE_UNKNOWN_APP_SOURCES,包安装程序无法安装应用程序。我无法在 MANAGE_UNKNOWN_APP_SOURCES 中修改该标志。

第二次尝试:

Log.e(TAG,layoutPath.getPath());
Runtime.getRuntime().exec("chmod 777 " + layoutPath.getPath());
Runtime.getRuntime().exec("pm install -r " + layoutPath.getPath());

结果:

Permission Denial: runInstallCreate from pm command asks to run as user -1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL

你有更好的想法吗?

标签: androidpermissionsandroid-things

解决方案


您可以使用Android Debug Bridge (adb)在您的设备上手动安装或更新应用程序。只要您指定了更高版本,使用此方法安装的应用程序版本将覆盖捆绑到工厂映像中的任何现有版本

有关使用 ADB 连接到特定设备的更多详细信息,请参阅硬件指南


推荐阅读