简体   繁体   English

Android:在后台从其他应用更新应用,而无需用户干预

[英]Android: Update app from another app in background without user intervention

I have an app 'A' of version 1 already installed in a Android device. 我已经在Android设备中安装了版本1的应用程序“ A”。 And another app 'B' which has version 2 APK of app 'A'. 另一个应用程序“ B”具有应用程序“ A”的版本2 APK。 The app 'B' should autamatically update the app 'A' with version 2. I have done it this way: 应用程序“ B”应自动以版本2更新应用程序“ A”。我这样做是这样的:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + apkPath), APK_MIMETYPE);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent); 

The problem is that it prompts for user intervention (asks to click on 'install' button) to update the app 'A'.I require the app 'A' to be updated silently in the background. 问题是它提示用户干预(要求单击“安装”按钮)以更新应用程序“ A”。我需要在后台静默更新应用程序“ A”。

Conditions: 条件:

  1. The device is not rooted. 设备未植根。
  2. System certificate keys are available. 系统证书密钥可用。 The app 'B' can be made to run as a system app with shareduserid as android.uid.system . 可以使应用程序“ B”作为系统应用程序运行,并且shareduserid为android.uid.system

Is it possible to do silent upgradation with the above conditions ? 在上述条件下是否可以进行静默升级? Can it be done from shell command programatically using Runtime.getRuntime().exec() API ? 是否可以使用Runtime.getRuntime().exec() API以编程方式从Shell命令完成此操作?

i don't think it can be achieved without user interaction.you can achieve it by simply a shell script which can install the application via package manager exmple script save it as and make sure to done chmod +x sample.sh via command line or shell 我认为没有用户交互就无法实现它。您可以通过一个简单的shell脚本来实现它,该脚本可以通过程序包管理器安装,例如将脚本另存为,并确保通过命令行或chmod + x sample.sh完成。贝壳

sample.sh sample.sh

 #!system/bin/sh

 pm install -r Myandroid_application_path/my.apk

Runtime.getRuntime().exec() may be it works for you but its not working for me in my galaxy note i hv tried this code u can try also and if it work pls update Runtime.getRuntime()。exec()可能对您有用,但在银河笔记中不适用于我,我尝试了此代码,您也可以尝试,如果可以工作请更新

            Process proc = null;

    try {
        Runtime rt = Runtime.getRuntime();
        Process proc= rt.exec("/system/bin/pm install -r /mnt/sdcard/chess.apk");

    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.d("in catch", ""+proc.getErrorStream());

    }

i hv read some some script runner in android as Gscript but i think its only owrk on rooted phone it is also not able to run in my galaxy note 我在Android中以Gscript的形式读取了一些脚本执行器,但我认为它只有根植在手机上,它也无法在我的银河笔记中运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM