【问题标题】:Force android app to open when it's installation complete安装完成后强制打开安卓应用
【发布时间】:2016-01-10 13:39:41
【问题描述】:

我正在运行一个 android 应用程序,它是系统上唯一运行的应用程序,因此,当启动完成时,我会启动该应用程序并阻止用户出于任何原因退出它(这使我禁用了两个导航状态栏)。

然后,为了实现对应用程序的更新,我查看是否有新的,如果有,我运行后台任务以使用jsch 从 sftp 服务器下载新的更新,当应用程序完成时下载,我使用ACTION_VIEW意图安装apk:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/update_app.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

这里的问题是安装完成后,出现默认的android屏幕:

这让用户可以选择完成 || 打开,并且确定如果用户选择完成,这将导致关闭窗口,并且应用程序在更新时已经关闭,因此它会将用户带到完全不受欢迎的系统用户界面。

请记住,我无法以编程方式打开应用程序,因为安装更新时它会卸载旧版本,因此我必须执行以下两个选项之一,但我不知道如何实现:

  1. 安装完成后强制应用默认打开。

  2. 更改系统安装完成屏幕或覆盖其按钮操作。

【问题讨论】:

  • 我的应用没有显示完成/打开对话框,你知道吗?

标签: android actionview android-install-apk android-os-handler


【解决方案1】:

我终于解决了这个问题,我在一个侧应用程序中使用了以下接收器:

    <receiver
        android:name="com.example.extraApp.InstallReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <data android:scheme="package"/>
        </intent-filter>
    </receiver>

这个应用程序一直在运行,它只包含那个接收器,在触发后(当原始应用程序更新时),我使用包名称来启动原始应用程序:

public class InstallReceiver extends BroadcastReceiver{    
    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            Intent new_intent = context.getPackageManager().getLaunchIntentForPackage("com.example.updaterjschtest");
            context.startActivity(new_intent);
        } catch (Exception e) {
            e.printStackTrace();
        }   
    }
}

关于为什么我确实使用另一个侧面应用程序作为监听器,那是因为BroadcastReceiver will never work unless the app is launched at least once,它在原始应用程序更新后无法直接通过。

【讨论】:

    【解决方案2】:

    我建议install_referrer (reference)

    就像在这个answer 中一样,我认为在onReceive 中你可以执行你想要的每一个代码,比如启动你的Activity。

    我从未使用或测试过这种方法,但它应该是可行的。

    【讨论】:

    • 哦,我明白了。不涉及 Google Play。
    • 不幸的是,这对我没有帮助 > 当从 Google Play 商店安装应用程序时,会广播 Google Play com.android.vending.INSTALL_REFERRER Intent。正如你所说,不涉及 google-Play
    • 如果您有兴趣了解,我已成功找到问题的解决方案。
    • com.android.vending.INSTALL_REFERRER 在安装后由 Market Play Store 广播,但仅当最终用户按下“打开”按钮。
    猜你喜欢
    • 1970-01-01
    • 2011-01-17
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多