android - 如何在使用 Intent.ACTION_PACKAGE_REMOVED 时查找已卸载的包名称

标签 android android-intent android-package-managers

我有一个应用程序,它记录了设备上安装的内部开发的应用程序。安装后,将调用 Intent.PACKAGE_ADDED 的广播接收器并使用以下代码记录包名称:

public class NewInstallReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Bundle b = intent.getExtras();
        int uid = b.getInt(Intent.EXTRA_UID);
        String[] packages = context.getPackageManager().getPackagesForUid(uid);

        ApplicationService appService = new ApplicationService(context);
        appService.ApplicationInstalled(packages);
    }
}

我面临的问题是,当为 Intent.PACKAGE_REMOVED 使用广播接收器时,所有通过唯一 ID (UID) 对包的引用都会返回空信息(如您所料,假设它已被卸载)。目前我有一个临时解决方案,但它不是很优雅,对于下一个版本我希望有更清晰的代码。代码应如何工作的示例:

public class RemoveApplicationReceiver extends BroadcastReceiver 
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Bundle b = intent.getExtras();
        int uid = b.getInt(Intent.EXTRA_UID);
        String[] packages = context.getPackageManager().getPackagesForUid(uid);

        ApplicationService appService = new ApplicationService(context);
        appService.ApplicationRemoved(packages);
    }

}

总结一下,问题是:

在删除程序后,如何在 Intent.PACKAGE_REMOVED 的广播接收器中引用包名称。

谢谢

最佳答案

包名在你从BroadcasReceiver得到的Intent中,使用“getData()”函数,有安装/卸载包的ComponentMame。

关于android - 如何在使用 Intent.ACTION_PACKAGE_REMOVED 时查找已卸载的包名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8910411/

相关文章:

android - 在 Android SDK 2.3 上编译的 Android 2.0 上运行应用程序时出现问题

Android ssl 握手异常映射 api

android - 如何创建一个携带数据的android Intent?

android - 如何从android中的另一个应用程序资源更改主题?

android - 如何确定 APK 是否与设备支持的 ABI 兼容?

Android java.lang.NoClassDefFoundError 使用 JODA 库

android - Android 上的 OpenGL 是电池 killer 吗?

android - NFC Tag扫描打开Goog​​le play下的Trigger app

android - 即使我的应用程序不工作,我的广播接收器也会执行

android - 添加 PACKAGE_USAGE_STATS [Android Lollipop] 时 Manifest.xml 出错