安装完成后强制打开android应用 [英] Force android app to open when it's installation complete

查看:216
本文介绍了安装完成后强制打开android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

然后,要实现对应用程序的更新,我查看是否有新的更新,如果有,我运行一个后台任务,使用

,这使用户可以选择完成 ||.打开,并确保用户是否选择完成会导致关闭窗口,并且应用程序在更新时已经关闭,因此将用户带到系统用户界面,根本不受欢迎.

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

  1. 在安装完成后,默认情况下强制打开应用程序.

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

解决方案

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

 <接收器android:name ="com.example.extraApp.InstallReceiver"android:exported ="true"><意图过滤器>< action android:name ="android.intent.action.PACKAGE_INSTALL"/>< action android:name ="android.intent.action.PACKAGE_ADDED"/>< data android:scheme ="package"/></intent-filter></receiver> 

此应用程序始终处于运行状态,除了接收者之外,什么都没有,这是在触发后(当原始应用程序更新时),我使用程序包名称启动原始应用程序:

 公共类InstallReceiver扩展了BroadcastReceiver {@Overridepublic void onReceive(Context context,Intent intent){尝试 {意图new_intent = context.getPackageManager().getLaunchIntentForPackage("com.example.updaterjschtest");context.startActivity(new_intent);} catch(Exception e){e.printStackTrace();}}} 


关于我为什么要使用另一个辅助应用程序作为侦听器的原因,这是因为jsch, and when the app finish downloading, I install the apk using ACTION_VIEW intent:

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);

The problem here is when the installation complete, the default android screen appears:

and this gives the user the option to choose Done || Open, and for sure if the user choose Done that will lead to close the window and the app is already closed now as it is updated, so it takes the user to the system UI which is not welcomed at all.

keep in mind that I can't open the app programmatically as when install the update it uninstall the old-version, so I've to do one of the two options which I don't know how to achieve any:

  1. Force the app to open by default after the installation finished.

  2. Change the system install finish screen or override it's buttons actions.

解决方案

I finally solved the problem, I used the following receiver in a side app:

    <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>

and this app is always running and it contain nothing but that receiver, which is after triggered(when the original app updated), I use the package name to launch the original app:

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();
        }   
    }
}


And about why I did use another side app as a listener, that's because the BroadcastReceiver will never work unless the app is launched at least once, which is not applicable through the original app directly after it got updated.

这篇关于安装完成后强制打开android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆