我有一个应用程序,它记录了设备上安装的内部开发的应用程序。安装后,将调用 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/