安装完成后强制打开android应用

编程入门 行业动态 更新时间:2024-10-24 12:22:18
本文介绍了安装完成后强制打开android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

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

  • 解决方案

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

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

    关于我为什么要使用另一个辅助应用程序作为侦听器的原因,这是因为,该更新在应用程序更新后不能直接通过原始应用程序使用.

    I'm running an android app to be the only app to run on the system, so, when boot-completed I launch the app and prevent the user from exiting it for any reason(which made me disable both navigation status bars).

    Then, to achieve an update to the app, I look if there is a new one, and if so, I run a background task to download the new update from the sftp server using 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:

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

  • 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应用

    本文发布于:2023-11-27 07:10:54,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1637087.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:安装完成后   android

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!