安卓:监听程序安装/升级广播消息 [英] Android: Listen for app installed / upgraded broadcast message

查看:156
本文介绍了安卓:监听程序安装/升级广播消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Lookout的应用程序(https://play.google.com/store/apps/details?id=com.lookout),我看到我安装或升级应用程序,每一次,它会自动扫描这个应用程序,以确保它的没有恶意。

Using Lookout app (https://play.google.com/store/apps/details?id=com.lookout), I see every time I install or upgrade app, it'll automatically scan this app to ensure it's not malicious.

按照山,我写了一个简单的应用程序,只要每个应用程序被安装或升级该听的广播消息。 AFAIK,有一些类型的IntentFilter的广播消息,它是:

Follow Lookout, I write a simple app which listen broadcast message whenever each app is installed or upgraded. AFAIK, there are some type of IntentFilter for broadcast message, it is:

  • Intent.ACTION_PACKAGE_ADDED
  • Intent.ACTION_PACKAGE_CHANGED
  • Intent.ACTION_PACKAGE_INSTALL

我希望 Intent.ACTION_PACKAGE_ADDED 的答案,但它是错误的(ACTION_PACKAGE_ADDED:一个新的应用程序包已经安装在设备上的数据包含了包的名称。请注意,新安装包不会收到该广播。),而 ACTION_PACKAGE_INSTALL 是德precated。

I hope Intent.ACTION_PACKAGE_ADDED is the answer but it's wrong (ACTION_PACKAGE_ADDED: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.) while ACTION_PACKAGE_INSTALL is deprecated.

谁能告诉我一个更好的办法?任何帮助是值得欢迎的。

Can anyone tell me a better way? Any help is welcome.

推荐答案

如果您正在安装一个应用程序,设备上的所有其他应用程序将获得意图该应用程序的是新安装的应用程序,但不是本身它不似乎有什么用途。现在,将获得节目,如果其他应用程序是后来安装或更改。

如果你想了解的,当你的应用程序安装或其他一些应用程序是最后安装或更新时,您可以随时使用PackageManager

If you are installing an application A, All other applications on the device will get the Intent that application A is the newly installed application but not A itself as it doesnt seem of any use. Now A will get broadcasts if other apps are later installed or changed.

If you want to find out at when your app was installed or some other app's the last install or update time, you can always use PackageManager

    PackageManager pm = context.getPackageManager();
 ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
 String appFile = appInfo.sourceDir; 
long installed = new File(appFile).lastModified();

在这里app.package.name是要找出安装时应用程序的包名。如果你想用它为你的应用程序,通过在您的应用程序包名称。

here app.package.name is the package name of the app you want to find out the install time. If you want to use it for your app, pass in your app's package name.

这篇关于安卓:监听程序安装/升级广播消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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