На корневом устройстве вы можете использовать этот код, который также возвращается к запросам подтверждения на некорневом устройстве. Это автоматически обновляет фактически запущенное приложение и перезапускает его.
// path is the complete path to the APK file, startActivityName is the name of the activity to start once the install is complete.
private boolean rootUpdateAPK(String path, String startActivityName)
{
final String libs = "LD_LIBRARY_PATH=/vendor/lib:/system/lib ";
final String[] commands = {
libs + "pm install -r " + path,
// libs + "reboot"
// };
libs + "am start -n " + this.getPackageName() + "/."+startActivityName
};
execute_as_root(commands); // not supposed to return if successful
// device is not rooted, let's do it the "regular" way.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return false;
}
private void execute_as_root(String[] commands) {
try {
Process p = Runtime.getRuntime().exec("su");
InputStream es = p.getErrorStream();
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for(String command : commands) {
TVLog.i(TAG,"Execute as root: "+command);
os.writeBytes(command + "\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
int read;
byte[] buffer = new byte[4096];
String output = new String();
while ((read = es.read(buffer)) > 0) {
output += new String(buffer, 0, read);
}
p.waitFor();
TVLog.i(TAG, output.trim() + " (" + p.exitValue() + ")");
} catch (IOException e) {
TVLog.i(TAG, e.getMessage());
} catch (InterruptedException e) {
TVLog.i(TAG, e.getMessage());
}
}
Если устройство «внедренное», возможно, тогда я дам вам код. Если нет, то это невозможно. – Wildcopper
без корня невозможно. Вот почему Amazon и Mikandi «магазины приложений» запрашивают подтверждение пользователя. – Budius
Это конкретное устройство. Я настраиваю android для этого устройства. – Pein