如何找到已经使用Intent.ACTION_PACKAGE_REMOVED卸载时,包名 [英] How to find the package name which has been uninstalled when using Intent.ACTION_PACKAGE_REMOVED

查看:665
本文介绍了如何找到已经使用Intent.ACTION_PACKAGE_REMOVED卸载时,包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是保持一个日志的设备上安装的内部开发的应用程序的应用程序。在安装广播接收机Intent.PACKAGE_ADDED被调用,使用下面的code记录了包名称:

I have an application which is keeping a log of internally developed applications installed on the device. Upon installation a broadcast receiver for Intent.PACKAGE_ADDED is invoked and records the package name using the following code:

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),​​所有参考的包回来与空信息(正如你所期望的,因为它已经被卸载)。我对其间治标不治本,但它不是很优雅,并为下一个版本我想有更清洁的code。的code应该是如何工作的一个例子:

The problem I'm facing is when using a broadcast receiver for Intent.PACKAGE_REMOVED, all reference to the package via the unique Id (UID) comes back with null information (As you would expect, given its already been uninstalled). I have a temporary solution for the meantime, but its not very elegant, and for the next version I would like to have cleaner code. An example of how the code should work:

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);
    }

}

因此​​,要回顾一下,问题是:

So to recap, the question is:

如何,程序已被删除后,可以参考我的包名在广播接收器Intent.PACKAGE_REMOVED。

How, after a program has been removed, can I reference the package name in a broadcast receiver for Intent.PACKAGE_REMOVED.

感谢

推荐答案

包名是从BroadcasReceiver得到了意图,用的getData()功能,还有就是安装/卸载程序包的ComponentMame。

The package names are in the Intent you got from BroadcasReceiver, use the "getData()" function, there is the ComponentMame of the installed/uninstalled package.

这篇关于如何找到已经使用Intent.ACTION_PACKAGE_REMOVED卸载时,包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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