在Android APK安装编程 [英] Install APK programmatically on android

查看:195
本文介绍了在Android APK安装编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让一个Android应用程序以编程方式对SD卡安装APK,但我遇到了一点小麻烦。

I've been trying to get an android application to install an APK on the sdcard programmatically but I'm running into a little trouble.

这是我怎么做的:

Intent intent = new Intent(Intent.ACTION_VIEW);           
intent.setDataAndType("ApkFilePath...","application/vnd.android.package-archive");
activity.startActivityForResult(intent,5000);

现在的工作好了,它带来的包管理器,我可以控制当经理完成安装APK做什么。

Now that works ok, it brings the package manager and I can control what to do when the manager finishes installing the APK.

但是,我遇到的问题是,如果在安装结束时,用户点击打开,而不是完成了OnActivityResult法不叫,为管理员仍然存在....这$ P $在系统上的其他要求psents另一个问题。

But the issue that I'm having is that if at the end of the installation the user clicks on "Open" instead of "Done" the "OnActivityResult" method is not called, as the manager still exists.... and this presents another issue on another requirement on the system.

有没有办法知道,当用户选择打开,在包管理器中结束,或者是有没有办法迫使经理只显示我希望它显示的按钮?

Is there a way to know when the user has selected "Open" at the end of the package manager, or is there a way to force the manager to display only the buttons I want it to display?

真正可以使用的帮助下,我已经搜索无处不在,似乎还没有找到一个解决办法

Really could use the help, I've search everywhere and don't seem to find a solution

推荐答案

您可以添加一个接收到你的的Andr​​oidManifest.xml 如果安装一个新的应用程序,听取广播。 像这样的:

You can add a receiver to your AndroidManifest.xml to listen to broadcasts if a new app is installed. Like this:

<receiver android:name=".PackageReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_CHANGED" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="package" />
    </intent-filter>
</receiver>

本类然后被安装了新的软件包时,名为:

This class then gets called when a new package is installed:

public class PackageReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    // handle install event here
  }
}

这篇关于在Android APK安装编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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