在 Android 中侦听已安装/升级的应用程序广播消息 [英] Listen for app installed / upgraded broadcast message in Android

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

问题描述

使用 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.

跟随 Lookout,我编写了一个简单的应用程序,每当安装或升级每个应用程序时,它都会收听广播消息.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: A new application package has been installed on the device. 数据包含包的名称.注意新安装的包不接收此广播.)而 ACTION_PACKAGE_INSTALL 已弃用.

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.

推荐答案

如果您正在安装应用程序 A,则设备上的所有其他应用程序都将获得应用程序 A 是新安装的应用程序的 Intent但不是 A 本身,因为它似乎没有任何用处.现在,如果以后安装或更改了其他应用程序,A 将收到广播.

如果您想了解应用的安装时间或其他应用的上次安装或更新时间,您可以随时使用 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 doesn't 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.

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

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