android – 如何查找使用Intent.ACTION_PACKAGE_REMOVED时卸载的软件包名称

前端之家收集整理的这篇文章主要介绍了android – 如何查找使用Intent.ACTION_PACKAGE_REMOVED时卸载的软件包名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个应用程序,它保存在设备上安装的内部开发的应用程序的日志.安装后,调用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.
原文链接:https://www.f2er.com/android/312815.html

猜你在找的Android相关文章